`await tick()` doesn't work when using in tests but `waitFor` does
macmillen opened this issue · 2 comments
macmillen commented
const user = userEvent.setup();
await user.type(inputElement, "{backspace}");
waitFor(() => expect(screen.getByTestId("super-auto-tag")).toHaveTextContent("Lukasz")); // this works
const user = userEvent.setup();
await user.type(inputElement, "{backspace}");
await tick(); // this doesn't work
expect(screen.getByTestId("super-auto-tag")).toHaveTextContent("Lukasz");
sebastianrothe commented
I have to use await tick();
multiple times (like 10x) for some of my tests.
yanick commented
I kinda expect this is caused by the expected output being dependent on something reacting to a change reacting to a change reacting to the original event, which would indeed takes several tick()
to stabilize.
Since tick()
is part of svelte itself, I don't think there is much we can do here. Using waitFor
seems to be the obvious and reasonable thing to do.