Mocking responses is great but what if you want to observe requests without affecting them? In this lesson, we will learn how to instruct Mock Service Worker to perform intercepted requests as-is.
Lecturer: [0:04] With MSW, returning mock responses from response resolvers is not mandatory. In fact, you can just observe the network traffic without affecting it in any way. All you have to do is be explicit about it. To do that, import the passThrough function from MSW. Create a request handler for the request you wish to observe or use any existing request handlers.
[0:20] As an example, let's modify the movie recommendations handler we already have. If we return the passThrough function call from this response resolver, MSW will perform this intercepted request as is. This means that the client will receive the original data.
[0:35] In our case, the data returned from the recommendationsLoader function in Remix. We can make great use of this pattern if we pass through requests conditionally. Let's return to the movie recommendations handler and pass-through this request only for a particular movie ID.
[0:57] This way, we can alternate between the mock data and the original data based on the requested resource.