Closed mitchconquer closed 4 years ago
+1 happens for me
@mitchconquer Yes, it was a mistake.
This is because of the delay error in the mockserviceworker.js file. You can start by modifying the documentation in the mockserviceworker.js file
after modification
setTimeout(
resolve.bind(this, createResponse(clientMessage)),
clientMessage.payload.delay,
)
We'll fix it as soon as possible
@hehehai that worked, thanks a lot!
Awesome, thanks!!
@hehehai, thank you for the fix! Indeed, since the message structure change I've overlooked where the delay
is stored. Your changes look good, will approve and release.
Note that by design you shouldn't modify the mockServiceWorker.js
directly. Once the patch is released, the library will suggest you to replace it with npx msw init
once more, which is the established way to propagate changes and fixes like this one to the worker file.
Released in 0.15.5
. Please update and run npx msw init <PUBLIC_DIR>
once more for the changes in the worker file to propagate to your project automatically.
Thank you once more for raising this and for a quick fix.
Describe the bug
Hi! I'm using MSW with Create React App Typescript and I'm having an issue getting the response delay to work. The MSW log message in the console does respect the response delay but the fetch response does not.
Environment
msw: ^0.13.1
nodejs: v13.12.0
npm: 6.14.4
react-scripts: 3.4.1
typescript: ^3.8.3
To Reproduce
I have created a code sandbox to try to reproduce this issue but cannot get it to work. Not sure if you have any guidance on that?
Steps to reproduce the behavior:
--template typescript
yarn add -D msw
npx msw init ./public
When fetch to route, the response comes back immediately but the MSW console message waits for the delay and then appears.
Expected behavior
I expect the response from the mock API to wait until the delay before returning. Is that a misunderstanding of the library?
Screenshots
I have created a GIF to show the issue. I put a console log around my fetch statement like below to show when the request starts and finishes.
In the GIF, I click the "load more customers" button and you can see the fetch response start and finish immediately while the MSW log waits 2000ms to appear.
In my mocked endpoint, if I add the following lines, the fetch response is correctly delayed.
Any idea what could be causing this issue? Thanks!