Skip to content

No responses with await response.json() when using Jest & undici polyfill #1829

Closed Answered by mattcosta7
jeffwong14 asked this question in Q&A
Discussion options

You must be logged in to vote

@jeffwong14 - I believe the issue stems from an implementation of fake timers in jest combined with the way node's fetch implementation, unidici works.

this doesn't seem to be something we can fix directly in MSW as far as I can tell, but instead we would need changes in undici.

I have more discovery as well as 2 workarounds here: #1830 (comment)


And the relevant workarounds copied here:

  1. use legacy fake times
  jest.useFakeTimers({
    now: hardCodeNow,
    legacyFakeTimers: true,
  });
  1. avoid faking queueMicrotask
  jest.useFakeTimers({
    now: hardCodeNow,
    doNotFake: ["queueMicrotask"],
  });

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@mattcosta7
Comment options

@jeffwong14
Comment options

Answer selected by mattcosta7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants