-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
snapshot in a waitFor doesn't seem to work right in 7.x #484
Comments
Just to be clear, you need to use |
Jest 25 (if you're using it) should be warning about dangling promises if you don't |
sorry that was just a typo, the issue is still the same when i add await. |
Jest's runner does stuff like run snapshot tests twice after they are changed to detect non-idempotent/deterministic snaps, so maybe that has something to do with it? |
Ah, yeah, so we should probably document this, but because of the way all of the
I literally just ran into this. Moving this issue to the docs repo so we can add a note about this. |
Inline is different than "regular" though; you'd get the same thing in a |
Oh, fair point. Moving back 😅 |
I think that this is still not recommended because the point of So yeah, don't use snapshots in the async utils. We should document this. I don't think we can do anything to change it... |
await waitFor(() => {
// expect(mockApi).toBeCalled(); // fails without this. but why? 🚩🚩🚩
expect(mockApi.mock.calls).toMatchSnapshot()
}) FWIW, it looks like that line with the 🚩 failing shortcircuits the wait by throwing, so it only moves onto the snapshot call one time. Which agrees with what Kent it saying, which is that calling it more than once will error. I think it's because of how the snapshot reporter works in Jest (ie, how it says "N snapshots updated" in the test report, how it runs the test twice when a snapshot is written, and has the interactive prompt to update in watch mode). It might work in some other implementation like a Mocha plugin. |
Going to go ahead and close this. If someone wants to do more with docs feel free. |
dom-testing-library
version: 10.xnode
version: 12.14npm
(oryarn
) version: 6.13Relevant code or config
when using
waitFor
withexpect().toMatchSnapshot()
I've seen some strange behaviors.What you did:
What happened:
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 wouldSuggested solution:
The text was updated successfully, but these errors were encountered: