atomiks / tippyjs

Tooltip, popover, dropdown, and menu library
https://atomiks.github.io/tippyjs/
MIT License
12.02k stars 521 forks source link

How to reset tooltip id between tests? #981

Closed lolobosse closed 3 years ago

lolobosse commented 3 years ago

Given the following tests:

   it("renders properly", async () => {
        const element = await fixture(<Tooltip content={"Hello Tooltip"} child={(toggle) => <div>Click Here</div>} />);
        expect(element).toMatchSnapshot();
    });

    it("reacts properly to click", async () => {
        const element = await fixture(
            <Tooltip content={"Hello Tooltip"} child={(toggle) => <div onClick={toggle}>Click Here</div>} />,
        );
        fireEvent.click(getByText(element, "Click Here"));
        await findByText(element.parentNode as HTMLElement, "Hello Tooltip");
        expect(element.parentNode).toMatchSnapshot();
    });

The element.parentNode gets different id for the tooltip (tippy-1 or tippy-2).

Is there a way to reset the tooltip id between each unit test to be able to run every unit test independently ?

atomiks commented 3 years ago

The id is autoincrementing so I don't think so. Can snapshots be replaced with other comparisons of the element?

atomiks commented 3 years ago

I've enabled Discussions for all questions to go inside instead of Issues.