Skip to content

Commit

Permalink
update symlink, rename unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseditson committed Sep 12, 2024
1 parent bab8dce commit 3fd0abe
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/integration/fixtures/todo-mvc-app/node_modules
60 changes: 58 additions & 2 deletions tests/unit/view-setup.spec.ts → tests/unit/tests.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import test, { before, describe } from "node:test";
import test, { after, afterEach, before, describe } from "node:test";
import assert from "node:assert/strict";
import { JSDOM } from "jsdom";
import { cre8, Upd8View } from "../../src/upd8";
import { rejects, throws } from "node:assert";

class TestMultiIDView extends Upd8View<{}, {}> {
static get id() {
Expand All @@ -19,7 +20,12 @@ class TestMultiIDView extends Upd8View<{}, {}> {
}
}

test("it chooses the outer-most of duplicate IDs when showing views", () => {
afterEach(async () => {
// Pause for gc - otherwise old instances will continue to respond to event listeners.
await new Promise((resolve) => setTimeout(resolve, 0));
});

test("it chooses the outer-most of duplicate IDs when showing views", async () => {
let dom = new JSDOM(
`<!DOCTYPE html><body><div id="different-view"><div id="multi-id" data-correct="no"></div></div><div id="multi-id" data-correct="yes"></div></body>`
);
Expand All @@ -46,6 +52,8 @@ test("it chooses the outer-most of duplicate IDs when showing views", () => {
(v) => v.checkView()
);
assert.equal(correct, "yes");
initUI.teardown();
dom.window.close();
});

describe("setContent", () => {
Expand Down Expand Up @@ -85,6 +93,10 @@ describe("setContent", () => {
});
upd8 = initUI({}, (event) => {});
});
after(() => {
initUI.teardown();
dom.window.close();
});
test("setContent without a selector returns one element", () => {
const val = initUI.imperative<SetContentTest, HTMLElement>(
SetContentTest.id,
Expand All @@ -106,3 +118,47 @@ describe("setContent", () => {
});
});
});

describe("mount", () => {
class InitError extends Upd8View<{}, {}> {
static get id() {
return "ie";
}

get id() {
return InitError.id;
}

mount(): Function[] {
return [this.eventListener("not-exist", "click", () => {})];
}
}
type RTC = ReturnType<typeof cre8<{}, {}>>;
let dom: JSDOM, initUI: RTC, upd8: ReturnType<RTC>;
before(() => {
dom = new JSDOM(
`<!DOCTYPE html><body>
<div id="ie"></div>
</body>`
);
initUI = cre8([InitError], {
document: dom.window.document,
});
upd8 = initUI({}, (event) => {});
});
after(() => {
initUI.teardown();
dom.window.close();
});
test("it emits a helpful error message when a listener fails to mount", async () => {
rejects(
async () => {
await upd8({});
},
{
message:
'[ie] eventListener failed: couldn\'t find element with id "not-exist" for click in <div id="ie"></div>',
}
);
});
});

0 comments on commit 3fd0abe

Please sign in to comment.