Skip to content

Commit 6ab543b

Browse files
committed
Test more generators, test UID
1 parent 63a9f1c commit 6ab543b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

test/generators/generators-test.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { test } from "tap";
1+
import {test} from "tap";
22
import filter from "../../src/generators/filter";
33
import map from "../../src/generators/map";
44
import range from "../../src/generators/range";
55
import valueAt from "../../src/generators/valueAt";
6+
import observe from "../../src/generators/observe";
7+
import queue from "../../src/generators/queue";
68

79
test("filter(value, fn) filters", t => {
810
function* input() {
@@ -35,3 +37,22 @@ test("valueAt(generator, i) picks a value", t => {
3537
t.equal(valueAt(input()), undefined);
3638
t.end();
3739
});
40+
41+
test("observe only yields the most recent value", async t => {
42+
let o = observe(change => {
43+
change(1);
44+
change(2);
45+
});
46+
t.equal(await o.next().value, 2);
47+
t.end();
48+
});
49+
50+
test("queue yields all values", async t => {
51+
let q = queue(change => {
52+
change(1);
53+
change(2);
54+
});
55+
t.equal(await q.next().value, 1);
56+
t.equal(await q.next().value, 2);
57+
t.end();
58+
});

test/index-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {test} from "tap";
22
import {Library, FileAttachments} from "../src";
3+
import UID from "../src/dom/uid";
34

45
test("new Library returns a library with the expected keys", async t => {
56
t.deepEqual(Object.keys(new Library()).sort(), [
@@ -25,3 +26,17 @@ test("FileAttachments is exported by stdlib/index", t => {
2526
t.equal(FileAttachments.name, "FileAttachments");
2627
t.end();
2728
});
29+
30+
test("UID", t => {
31+
global.location = "https://test.com/";
32+
const hi = UID("hi");
33+
t.deepEqual(hi, {
34+
id: "O-hi-1",
35+
href: "https://test.com/#O-hi-1"
36+
});
37+
t.equal(hi.toString(), "url(https://test.com/#O-hi-1)");
38+
39+
const anon = UID();
40+
t.equal(anon.toString(), "url(https://test.com/#O-2)");
41+
t.end();
42+
});

0 commit comments

Comments
 (0)