msw in testcafe says its started, but responds with 404
See original GitHub issueDescribe the bug
I am attempted to use msw in conjunction with testcafe (the best e2e testing tool for node, yeah even better than cypress, shamless plug).
testcafe has good docs about running service workers & https features in tests which I am following.
When I run the test, I can see it says [MSW] Mocking enabled
but then none of the fetches are working.
Environment
msw: 0.19.4
nodejs: v12.16.1
yarn:1.22.4
Please also provide your browser version. chrome 83
To Reproduce
Steps to reproduce the behavior:
- Clone https://github.com/benmonro/msw-server/tree/feature/testcafe (note repro for this is on a branch called
feature/testcafe
) (cd app && yarn)
yarn
yarn testcafe
- testcafe will launch a browser, Once the browser loads you can launch chrome dev tools and see the 404 as shown in the above screenshot.
If you’d like to see this working in the actual app:
- (cd app && yarn dev)
- you can then add a todo or click a todo to remove one.
that all goes through msw and works fine. it only seems to be problematic over testcafe’s proxy server.
Expected behavior
expecting fetch calls to be mocked.
Screenshots
If applicable, add screenshots to help explain your problem. (see above)
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (18 by maintainers)
Top Results From Across the Web
Newest 'msw' Questions - Stack Overflow
I am trying to mock post request to api that returns status of 404, so after it returns response i can display an...
Read more >Debugging uncaught requests - Recipes - Mock Service Worker
A request to /user or /posts will not be intercepted as they lie outside of the worker's scope ( /assets ). The Service...
Read more >RequestMock Class | Test API | API | Docs - TestCafe
A request mocker that intercepts requests to a web resource and emulates the response. Use the RequestMock constructor to create a mocker.
Read more >Untitled
Pronatours puerto morelos, Start of wisdom teeth coming in, Shiva nataraja artist, ... Like an onion but not, Abend sa13-10, Uefa women's under...
Read more >Untitled
Mayor of jackson ms, Gnagarforum aftonbladet plus, Impatiens zombensis, Bates motel norma and norman fanfiction. Contoh perjanjian kredit bank, ...
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
@kettanaito I have a fix, but I’m not sure where to put a test to capture the fix, would you mind pointing me in the right place? I just have to add a null check for req.body.query and it seems to fix it.
Hey, I’m glad to see it running!
The usage of asterisk proves that the issue is with the proxy URL that Testcafe prepends. While asterisk would work, it’s generally not recommended, as it literally matches
<ANYTHING>/todos
, which may lead to unexpected matches.I recommend to look into the Testcafe API and grab its prepended URL during the test runtime. Then use that URL when resolving a request handler’s route. Here’s an example: