-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Mocking changes returned promises #5647
Comments
This is a documented difference from Jest: #3634 I am open to discuss the change to how it works. |
Oh I couldn't find it in the mocking docs. I wasn't doing a migration and didn't look there, I just mentioned Jest to constrast. Heeding your openness to discussion, I was testing this UI update and it wasn't happening due to the promises being changed by a mock. In order for these kind of tests to work with vitest, the developer would have to carefully consider what to mock/spy, or to extract parts of the implementation returning promises into unmocked functions. |
I just read the migration guide Accessing the Return Values of a Mocked Promise, but I think that even after reading it, I would have not been able to extrapolate that it means Vitest would change the returned promise of a mocked function. I understand it is perhaps a rare case to check up and compare promises directly (instead of await/then), but it feels like if the framework is changing the behavior of the code, it should be very explicit about it. Thanks for understanding. |
Describe the bug
A promise returned by a mocked function or methods, changes a returned promise.
i.e., saving the promise in a variable before returning it and then comparing it to what's returned outside the function with
===
evaluates to false.I can't find documentation for this and it doesn't happen with jest, so I suppose it's unintended.
Code from the StackBlitz link just in case:
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-zkjejn?file=src%2Fbasic.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: