Skip to content

Commit

Permalink
missing tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
johan-gorter committed Jan 31, 2024
1 parent 92878b0 commit 1d12b78
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion test/projector-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "path";

import { SinonStub } from "sinon";

import { MaquetteComponent, Projector, createProjector, h } from "../src/index";
import { MaquetteComponent, Projector, createProjector, h, dom } from "../src/index";
import { expect, sinon } from "./test-utilities";

describe("Projector", () => {
Expand Down Expand Up @@ -379,6 +379,26 @@ describe("Projector", () => {
expect(handleClick).to.be.calledOn(button);
expect(handleClick.lastCall.args[0].type).to.equal("click");
});

it("can add event handlers using on without an interceptor", () => {
let parentElement = { appendChild: sinon.stub(), ownerDocument: document };
let onClick = sinon.spy();
dom.append(parentElement as unknown as HTMLElement, h("button", { on: { click: onClick } }));
let button = parentElement.appendChild.lastCall.args[0] as HTMLElement;
button.dispatchEvent(new Event("click"));
expect(onClick).to.be.calledOnce;
});

it("can handle interceptors removing event handlers", () => {
let parentElement = { appendChild: sinon.stub(), ownerDocument: document };
let onClick = sinon.spy();
dom.append(parentElement as unknown as HTMLElement, h("button", { on: { click: onClick } }), {
eventHandlerInterceptor: () => undefined,
});
let button = parentElement.appendChild.lastCall.args[0] as HTMLElement;
button.dispatchEvent(new Event("click"));
expect(onClick).to.not.be.called;
});
});

it("can detach a projection", () => {
Expand Down

0 comments on commit 1d12b78

Please sign in to comment.