import { Component, mount, xml } from "../../src"; import { makeTestFixture, nextTick, snapshotEverything } from "../helpers"; snapshotEverything(); let fixture: HTMLElement; beforeEach(() => { fixture = makeTestFixture(); }); // ----------------------------------------------------------------------------- // t-set // ----------------------------------------------------------------------------- describe("t-set", () => { test("t-set outside modified in t-if", async () => { class Comp extends Component { static template = xml`

`; state = { flag: "if" }; } const comp = await mount(Comp, fixture); expect(fixture.innerHTML).toBe("

2

"); comp.state.flag = "elif"; comp.render(); await nextTick(); expect(fixture.innerHTML).toBe("

3

"); comp.state.flag = "false"; comp.render(); await nextTick(); expect(fixture.innerHTML).toBe("

4

"); }); test("t-set in t-if", async () => { // Weird that code block within 'if' leaks outside of it // Python does the same class Comp extends Component { static template = xml`

`; state = { flag: "if" }; } const comp = await mount(Comp, fixture); expect(fixture.innerHTML).toBe("

2

"); comp.state.flag = "elif"; comp.render(); await nextTick(); expect(fixture.innerHTML).toBe("

3

"); comp.state.flag = "false"; comp.render(); await nextTick(); expect(fixture.innerHTML).toBe("

4

"); }); test("t-set can't alter component even if key in component", async () => { class Comp extends Component { static template = xml`

`; iter = 1; } const comp = await mount(Comp, fixture); expect(fixture.innerHTML).toBe("

1

5

"); expect(comp.iter).toBe(1); }); test("t-set can't alter component if key not in component", async () => { class Comp extends Component { static template = xml`

`; } const comp = await mount(Comp, fixture); expect(fixture.innerHTML).toBe("

5

"); expect((comp as any).iter).toBeUndefined(); }); test("slot setted value (with t-set) not accessible with t-esc", async () => { class Childcomp extends Component { static template = xml`
`; } class Comp extends Component { static components = { Childcomp }; static template = xml`

`; } await mount(Comp, fixture); expect(fixture.innerHTML).toBe("

source

called

source

"); }); test("t-set not altered by child comp", async () => { let child; class Childcomp extends Component { static template = xml`
`; iter = "child"; setup() { super.setup(); child = this; } } class Comp extends Component { static components = { Childcomp }; static template = xml`

`; } await mount(Comp, fixture); expect(fixture.innerHTML).toBe("

source

childcalled

source

"); expect((child as any).iter).toBe("child"); }); });