Closed onlywei closed 10 months ago
Hi, @onlywei.
Yes, you can intercept all HTTP requests with MSW by using the http.all()
request handler. It's designed to allow request method-agnostic interception. You can both provide a specific path or provide an wildcard to capture all requests:
http.all('*', ({ request, cookies }) => {
// Handle ALL requests your application makes.
})
Hi @kettanaito. Thank you for the reply. I don't think that was my question though. I'm not worried about request methods. What I'm experiencing is that the wildcard "*
" isn't capturing my request. I still get this:
[MSW] Warning: captured a request without a matching request handler:
Even when I use .all('*'
...
@onlywei, I mentioned methods because request interception is method first, path second.
If there are still requests that don't match http.all()
, I highly recommend following the Debugging runbook. Let me know how far you get there.
MSW seems to require me to write down a very specific URL in order to capture my request in Jest. I just want to set up a server to capture every request regardless of the URL and then. turn the server off after my tests are finished.
I've tried the following:
.get('*'
.get(/.*/
.get(/**
None of these have worked.