import { renderToString, renderToBdom, snapshotEverything, makeTestFixture } from "../helpers"; import { mount, patch } from "../../src/runtime/blockdom/index"; snapshotEverything(); describe("t-key", () => { test("can use t-key directive on a node", () => { const template = `
`; expect(renderToString(template, { beer: { id: 12, name: "Chimay Rouge" } })).toBe( "
Chimay Rouge
" ); }); test("can use t-key directive on a node as a function", () => { const template = `
`; const getKey = (arg: any) => arg.id; expect(renderToString(template, { getKey, beer: { id: 12, name: "Chimay Rouge" } })).toBe( "
Chimay Rouge
" ); }); test("can use t-key directive on a node 2", async () => { const template = `
`; const bd = renderToBdom(template, { beer: { id: 12, name: "Chimay Rouge" } }); const fixture = makeTestFixture(); await mount(bd, fixture); const div = fixture.firstChild; expect((div as HTMLElement).outerHTML).toBe("
Chimay Rouge
"); const bd2 = renderToBdom(template, { beer: { id: 13, name: "Chimay Rouge" } }); await patch(bd, bd2); expect(div !== fixture.firstChild).toBeTruthy(); expect((div as HTMLElement).outerHTML).toBe("
Chimay Rouge
"); }); test("t-key directive in a list", () => { const template = ``; expect( renderToString(template, { beers: [{ id: 12, name: "Chimay Rouge" }], }) ).toBe(""); }); test("t-key on sub dom node pushes a child block in its parent", async () => { const template = `

`; expect(renderToString(template, { key: "1" })).toBe("

"); expect(renderToString(template, { hasSpan: true, key: "1" })).toBe( "

" ); const template2 = `

`; expect(renderToString(template2, { key: "1" })).toBe("

"); }); test("t-key: interaction with t-esc", async () => { const template = `

`; expect(renderToString(template, { key: "1", text: "abc" })).toBe("

abc

"); }); });