Skip to content
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

fix: apply response delay conditionally #1300

Merged
merged 2 commits into from Jun 22, 2022
Merged

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Jun 22, 2022

Changes

  • Removes setTimeout from the handleRequest so that response lookup is not concerned with actually applying a response (delaying it is, in fact, a part of applying it).
  • Manually delays mocked responses in Node.js only if delay has been set.
  • Adds a new integration test for ctx.delaty in Node.js.

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit ebe149b:

Sandbox Source
MSW React Configuration

@kettanaito
Copy link
Member Author

As responses are not always delayed now (previously always delayed by either 0 or custom delay duration), I'd expect the fake timers in Jest to work fine with MSW now:

  • Not using delay: no need to advance the fake timer, response is instantaneous.
  • Using delay: advance the timer by the delay duration, that should work.

@kettanaito kettanaito merged commit 496154d into main Jun 22, 2022
@kettanaito kettanaito deleted the fix/remove-constant-timeout branch June 22, 2022 15:17
@kettanaito
Copy link
Member Author

Released: v0.42.3 🎉

This has been released in v0.42.3!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No response when using jest.useFakeTimers() with axios and msw
1 participant