Description
dom-testing-library
version: 10.xnode
version: 12.14npm
(oryarn
) version: 6.13
Relevant code or config
when using waitFor
with expect().toMatchSnapshot()
I've seen some strange behaviors.
What you did:
test("should match snapshot async", async () => {
const mockApi = jest.fn();
render(<App callApi={mockApi} />);
fireEvent.click(screen.getByText("click me"));
await waitFor(() => {
// expect(mockApi).toBeCalled(); //fails without this. but why?
expect(mockApi.mock.calls).toMatchSnapshot()
})
})
test("should show stuff", async () => {
render(<App />);
waitFor(() => {
expect(document.body).toMatchSnapshot();
});
});
Reproduction repository:
https://github.com/testing-library/dom-testing-library-template
https://github.com/benmonro/rtl-wait-for-issue
Problem description:
expect.toMatchSnapshot doesn't seem to work properly in a waitFor. You'll notice i have 2 different usages. one in which the dom doesn't change, it just calls an api and matches on the mock for that api. another where it waits for a snapshot of the dom to match. My examples are a bit contrived, but they do highlight the problem we're seeing. I would of course use getByText to look for 'stuff' but it still makes me wonder why this usage of waitFor
isn't working w/ toMatchSnapshot the way I would think it would
Suggested solution: