Can I use this to test my own service worker implementation? #683
-
It sounds like this package is meant to mock service requests from my web app. But I'm looking to create my own service worker, which, as I have found out is not the easiest thing to unit test and even some integration level testing and e2e testing becomes problematic. Would msw be a good fit to unit test my own service worker? I know you can only have 1 service worker registered, so I assume this might even make things more complicated for me. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey, @dethstrobe. I don't think you should use MSW to test a custom Service Worker. MSW uses a Service Worker to intercept HTTP requests and then give you control over their responses. The worker is treated as an implementation detail. The library doesn't expose any means to test a worker. I think you may be looking for something like service-worker-mock (pardon the naming confusion). I haven't used that package, but it seems to be designed for testing workers, which is what you're after. |
Beta Was this translation helpful? Give feedback.
Hey, @dethstrobe.
I don't think you should use MSW to test a custom Service Worker. MSW uses a Service Worker to intercept HTTP requests and then give you control over their responses. The worker is treated as an implementation detail. The library doesn't expose any means to test a worker.
I think you may be looking for something like service-worker-mock (pardon the naming confusion). I haven't used that package, but it seems to be designed for testing workers, which is what you're after.