Function use() not work in browser
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0.36.8 |
browser | Chrome |
Request handlers
browser.ts
import { rest, setupWorker } from 'msw';
const worker = setupWorker(...);
window.msw = {
worker,
rest,
};
export { worker };
worker.ts
import { worker } from '../../mocks/browser';
export const setupMsw = () => {
return worker.start({
onUnhandledRequest: 'bypass',
serviceWorker: {
url: process.env.CI ? SOME_PATH/mockServiceWorker.js : '/mockServiceWorker.js',
},
}).then(() => {
window.msw.ready = true;
});
};
Current behavior
- Open the page where mock url uses
- Check that mock url fired correctly and mock data received successfully
- Open browser console and try to change mock data with use() function
window.msw.worker.use(
window.msw.rest.get('**/rest/shops', (_req, res, ctx) => {
return res(
ctx.json([]),
);
}),
);
- Try to use printHandlers() function. I see old and new mock urls
window.msw.worker.printHandlers()
[rest] GET /rest/shops
—- SOME OTHERS —-
[rest] GET /rest/shops
- Try to fetch mock url one more time in browser console
fetch('/rest/shops')
- I can see 2 debug messages in browser console (old and new mocks fired)
[MSW] 14:01:37 GET /rest/shops (200 OK)
[MSW] 14:01:37 GET /rest/shops (200 OK)
- Response from fetch are equal old mock (not new from use() function)
Expected behavior
- Response from fetch are equal new mock
I try to write e2e test with PlaywrightJs and in my test use() function working not correct. So, I try to reproduce my case in browser and I see the same error which I described earlier.
Could you help me with this issue Thank you!
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
JS function works in all browsers but not all machines
1 Answer 1 · open the dev tools · switch to the Performance Tab · click "Record" (top left round icon) · do...
Read more >Handling common JavaScript problems - MDN Web Docs
This includes information on using browser dev tools to track down and fix problems, using Polyfills and libraries to work around problems, ...
Read more >Differences between using a workbook in the browser and in ...
A workbook in this format can be opened but macros do not run in a browser window. ... Most Excel functions work in...
Read more >Activate JavaScript in your browser - Google AdSense Help
Open Chrome on your computer. Click More and then Settings. Click Security and Privacy. Click Site settings. Click JavaScript. Select Sites can use...
Read more >How to enable JavaScript in your browser and why
Nowadays almost all web pages contain JavaScript, a scripting programming language that runs on visitor's web browser. It makes web pages functional for ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@florianmatz Yes, I have got two workers.start() in different place of app.
@kazeichev Mmhhh… And how did you find out? Did you have two worker.start() or something?