Giter VIP home page Giter VIP logo

Comments (3)

sheremet-va avatar sheremet-va commented on July 23, 2024

This is a documented difference from Jest: #3634

I am open to discuss the change to how it works.

from vitest.

miguel-leon avatar miguel-leon commented on July 23, 2024

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.

miguel-leon avatar miguel-leon commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.