Is it possible to use MSW with Jest to simulate offline network conditions? Alternatively non MSW based solutions would suffice. I also don't want to mock navigator.onLine as I want to test the error path when a network request fails due to being offline.
Yes you can simulate a network error:
rest.get('/user', (_, res) => {
return res.networkError('Custom network error message')
})
Here is the related documentation: https://mswjs.io/docs/api/response/network-error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With