Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以将 MSW 与 Jest 一起使用来模拟离线网络条件?或者,非基于 MSW 的解决方案就足够了。我也不想模拟navigator.onLine,因为我想在网络请求因离线而失败时测试错误路径。
navigator.onLine
是的,您可以模拟网络错误:
rest.get('/user', (_, res) => { return res.networkError('Custom network error message') })
以下是相关文档:https ://mswjs.io/docs/api/response/network-error