Comments (3)
This is a documented difference from Jest: #3634
I am open to discuss the change to how it works.
from vitest.
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.
Although it took me some time to find out it was the mock changing the expected behavior of the function.
Perhaps consider adding a warning in the mocking guide?
Heeding your openness to discussion,
My use case is that If I have (due to user interaction) subsequent async calls (fetch), besides doing stuff with all awaited values, I also have to, say, update the UI only in response of the user's last interaction.
I accomplish this by saving the last promise, and after awaiting, compare the awaited promise with the last saved.
This ensures doing the work on the last interaction even if earlier promises resolve later.
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.
from vitest.
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.
from vitest.
Related Issues (20)
- False negative with typecheck enabled HOT 4
- (v2) `Error: Failed to load url` when dynamic importing js files generated during tests with relative path HOT 4
- Istanbul: Coverage ignore doesn't work for default in switch HOT 3
- Type error on mockImplementation with call signature in object type HOT 3
- Vitest failing to bundle nested dependency while Vite succeeds HOT 2
- Scoped Fixtures HOT 2
- Vitest v2 reports zero coverage for types-only TypeScript files HOT 7
- Vitest v2 coverage is reporting 'Unexpected reserved word' error HOT 4
- [@vitest/web-worker] Cannot acces the crypto API from vitest web worker
- Coverage report does not include types-only TS files HOT 1
- Global coverage threshold should not exclude glob based thresholds HOT 1
- Support 100 shorthand option for pattern based coverage rules HOT 1
- Istanbul failing to report coverage for CJS requires HOT 3
- Vitest Startup Error HOT 3
- File system mocking example doesn't work
- Terminal UI flickering HOT 1
- Bug Report: userEvent click causing test timeout in Vitest but works in Jest HOT 4
- TypeScript errors when mocking overloaded functions
- Bug: `testNamePattern` option unnecessarily requires a leading space for an exact match.
- Cannot read properties of undefined (reading 'navigator') when using `@vitest/browser` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vitest.