import { Component, mount, useState, xml } from "../../src"; import { makeTestFixture, nextTick, snapshotEverything } from "../helpers"; let fixture: HTMLElement; snapshotEverything(); beforeEach(() => { fixture = makeTestFixture(); }); describe("hydration", () => { test("can hydrate a simple static component", async () => { fixture.innerHTML = "
giuoco pianissimo
"; const target = fixture.firstChild as any; class Test extends Component { static template = xml`
giuoco pianissimo
`; } await mount(Test, target, { hydrate: true }); expect(fixture.innerHTML).toBe("
giuoco pianissimo
"); expect(fixture.firstChild).toBe(target); }); test("can hydrate a component with a handler", async () => { fixture.innerHTML = "
0
"; const target = fixture.firstChild as any; class Counter extends Component { static template = xml`
`; state = useState({ value: 0 }); inc() { this.state.value++; } } await mount(Counter, target, { hydrate: true }); expect(fixture.innerHTML).toBe("
0
"); expect(fixture.firstChild).toBe(target); target.click(); await nextTick(); expect(fixture.innerHTML).toBe("
1
"); }); test("can hydrate a component with a sub component", async () => { fixture.innerHTML = "

"; const target = fixture.firstChild as any; class Counter extends Component { static template = xml``; state = useState({ value: 0 }); inc() { this.state.value++; } } class Parent extends Component { static template = xml`

`; static components = { Counter }; } await mount(Parent, target, { hydrate: true }); expect(fixture.innerHTML).toBe("

"); expect(fixture.firstChild).toBe(target); target.querySelector("button")!.click(); await nextTick(); expect(fixture.innerHTML).toBe("

"); }); });