'
);
});
test("can use 2 refs with same name in a t-if/t-else situation", async () => {
class Test extends Component {
static template = xml`
`;
state = useState({ value: true });
ref = useRef("coucou");
}
const test = await mount(Test, fixture);
expect(fixture.innerHTML).toBe("");
expect(test.ref.el!.tagName).toBe("DIV");
test.state.value = false;
await nextTick();
expect(fixture.innerHTML).toBe("");
expect(test.ref.el!.tagName).toBe("SPAN");
test.state.value = true;
await nextTick();
expect(fixture.innerHTML).toBe("");
expect(test.ref.el!.tagName).toBe("DIV");
});
test("throws if there are 2 same refs at the same time", async () => {
const consoleWarn = console.warn;
console.warn = jest.fn();
class Test extends Component {
static template = xml`
`;
state = useState({ value: true });
ref = useRef("coucou");
}
await expect(async () => {
await mount(Test, fixture);
}).rejects.toThrowError("Cannot have 2 elements with same ref name at the same time");
expect(console.warn).toBeCalledTimes(1);
console.warn = consoleWarn;
});
test("refs and recursive templates", async () => {
class Test extends Component {
static components = {};
static template = xml`