Skip to content

snapshot in a waitFor doesn't seem to work right in 7.x #484

Closed
@benmonro

Description

@benmonro
  • dom-testing-library version: 10.x
  • node version: 12.14
  • npm (or yarn) 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();
  });
});

What happened:
image
image

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions