mswjs / http-middleware

Spawn an HTTP server from your request handlers or apply them to an existing server using a middleware.

Home Page:https://npm.im/@mswjs/http-middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discussion : mswjs/http-middleware to serve mock data for visual regression tests

KishaniKandasamy opened this issue · comments

Hi everyone , Is there any getting started guide to mock data for visual regression tests using mswjs/http-middleware?

Hey, @KishaniKandasamy.

Frankly, I think you'll get far better results by using MSW directly. Using @mswjs/http-middleware implies running a standalone mocking server. Apart from the runtime cost of that, you'd have to stir your entire application to communicate with that said server. That kind of deviation means you're no longer testing the same app as your users see.

With MSW, however, you enable request interception on the network level and can keep requesting the same resources from the production endpoints in your regression tests. Obviously, their responses will be mocked according to your requirements. We've got a good Getting started tutorial you can follow to get an idea of what the integration of MSW would look like for your tests.