import { createBlock, mount, multi, patch } from "../../src/blockdom"; import { makeTestFixture } from "./helpers"; //------------------------------------------------------------------------------ // Setup and helpers //------------------------------------------------------------------------------ let fixture: HTMLElement; beforeEach(() => { fixture = makeTestFixture(); }); afterEach(() => { fixture.remove(); }); describe("before remove is called", () => { test("simple removal", async () => { const block1 = createBlock("
coucou
"); const child = block2(); const tree = block1([], [child]); mount(tree, fixture); expect(fixture.innerHTML).toBe("coucou
coucou
"); let n = 1; child.beforeRemove = () => n++; patch(tree, block1([], []), true); expect(fixture.innerHTML).toBe(""); expect(n).toBe(2); }); test("remove a child of a multi", async () => { const block1 = createBlock("coucou
"); const child1 = block2(); const child2 = block2(); const tree = block1([], [multi([child1, child2])]); mount(tree, fixture); expect(fixture.innerHTML).toBe("coucou
coucou
coucou
"); const child1 = block2(); const child2 = block2(); const tree = block1([], [multi([child1, child2])]); mount(tree, fixture); expect(fixture.innerHTML).toBe("coucou
coucou