import { Component, mount, useRef, useState } from "../../src/index"; import { makeTestFixture, nextTick, snapshotEverything } from "../helpers"; import { xml } from "../../src/index"; snapshotEverything(); let fixture: HTMLElement; beforeEach(() => { fixture = makeTestFixture(); }); describe("refs", () => { test("basic use", async () => { class Test extends Component { static template = xml`
`; button = useRef("div"); } const test = await mount(Test, fixture); expect(test.button.el).toBe(fixture.firstChild); }); test("refs are properly bound in slots", async () => { class Dialog extends Component { static template = xml``; } class Parent extends Component { static template = xml`
`; static components = { Dialog }; state = useState({ val: 0 }); button = useRef("myButton"); doSomething() { this.state.val++; } } const parent = await mount(Parent, fixture); expect(fixture.innerHTML).toBe( '
0
' ); parent.button.el!.click(); await nextTick(); expect(fixture.innerHTML).toBe( '
1
' ); }); });