How to develop an offline Front-End app with mock data
- Written by
Rui Saraiva- Published
- Last updated
Have you ever wondered how to develop a Front-End project without relying on the API being ready and available to fetch data from?
In this tutorial, Iāll share different approaches to how you can do just that, starting by setting up a mock server and then showing how to integrate the mock server into multiple front-end environments ā development, test, and component development environments.
Here we go!
Previous experience with mock servers
From previous experience, Iāve used mock servers based on Express.js (opens in a new tab) where I would spin up the mock server and then any other environment server that would target HTTP requests to it.
Although this pattern is very flexible in the way we can use any 3rd party packages we want inside our mock server, it wasnāt always the best fit for being used across the front-end stack environments.
As an example, one common tool we use on front-end projects to develop components is Storybook, and when we get to the part where we assemble pages, more often than not, we have data requirements that need to be fetched from somewhere.
Some of this data can be stored locally on the project and delivered by its own mock server, but what about data coming from 3rd party services?
This case is something that an Express.js mock server wonāt cover if your codebase is making the requests directly to the 3rd party services. One way to get around this is by making custom endpoints on the mock server that mock the response from those same 3rd party services. This implies one layer of abstraction on our mock server that may not match our codebase data fetching strategy.
A front-end project should behave the exact same way with or without a mock server. If we start introducing conditionals on our code to handle both scenarios, thatās one extra piece of code we need to maintain.
There is another scenario where using an Express.js mock server for our Storybook environment isnāt a perfect fit. We can use it just fine on our local machines, but what about deploying our Storybook project to something like Chromatic?
When developing locally, we run both the Storybook development server and the Express.js mock server as well, but the same wonāt happen when we deploy it.
To deploy a Storybook project, we first build the production version of it, which is a static SPA version of it. This static build is deployed to any server that can deliver static assets, but the mock server isnāt deployed with it.
It would be great to have a mock server that can be used both locally and in āproductionā environments without any extra setup/configuration.
Enter Mock Service Worker (opens in a new tab) (MSW), a library that provides a seamless API for mocking on the browser and Node.js. Itās being marketed as an āAPI mocking of the next generationā on their website, and it does the mocking by intercepting requests on the network level.
It mentions that it can be used to reuse the same mock definition for testing, development seamlessly, and debugging.
This kind of seamless integration is what we are aiming for today!
The end goal is to start with the repo from the How to set up a front-end project with Vite, React, and TypeScript blog post (opens in a new tab) as a baseline, add new components with external data requirements and mock those exact requirements with MSW.
MSW for the win
To get us started, weāre going to build upon the project created in the How to set up a front-end project with Vite, React, and TypeScript blog post (opens in a new tab):
git clone [email protected]:Pixelmatters/setup-project-demo.git project-demo-msw
cd project-demo-msw
npm installThis will clone the repository into a folder called project-demo-msw and install the NPM dependencies as well.
New component with external data requirements
Letās create a new component that fetches some data from an external API and then renders some UI accordingly.
mkdir src/components
touch src/components/users.tsxHereās a simple React component with static HTML that you can copy to the src/components/users.tsx file:
export const Users: React.FC = () => {
return (
<div>
<h1>Users</h1>
<ul>
<li>User 1</li>
<li>User 2</li>
<li>User 3</li>
</ul>
</div>
)
}Before we continue making more changes, letās first create a new Story so we can preview this component in the Storybook environment:
touch src/components/users.stories.tsxNow you can copy the code below to configure the Story file with our new Users component:
import { ComponentStory, ComponentMeta } from '@storybook/react'
import { Users } from './users'
export default {
title: 'Components/Users',
component: Users,
} as ComponentMeta<typeof Users>
const Template: ComponentStory<typeof Users> = (args) => <Users {...args} />
export const Default = Template.bind({})Itās time to run our Storybook development environment and see our component being rendered:
npm run storybook
Now weāre going to update the component to make an HTTP request to an API to fetch some fake usersā data to replace our current static usersā list.
The API that we are going to use is called JSONPlaceholder, and more information about it can be found here (opens in a new tab).
To make the HTTP request, we will use the browser Fetch API (opens in a new tab). We will also need to store the data coming from the API in our React component. For that, we will use Reactās useState hook to manage our reactive state and the useEffect hook to integrate our async HTTP request code into React.
For more information on making an HTTP request inside React, you can check this documentation (opens in a new tab).
Hereās what our src/components/users.tsx component looks like with the API request in place:
import { useEffect, useState } from 'react'
type User = {
id: number
name: string
}
export const Users: React.FC = () => {
const [users, setUsers] = useState<User[]>([])
useEffect(() => {
fetch('https://jsonplaceholder.typicode.com/users')
.then((res) => res.json())
.then((result: User[]) => {
setUsers(result)
})
.catch(console.error)
}, [])
return (
<div>
<h1>Users</h1>
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
</div>
)
}We fetch the usersā data from the JSONPlaceholder API and then save it to the usersā state variable by calling the setUsers method with the response result.

Now weāre rendering the users that the JSONPlaceholder API returned, but what if the API request simply fails?
We can trigger this scenario by making our browser behave in an offline manner if we switch the network condition to offline on the developer tools. The following example is on the Brave Browser, which is Chromium-based, so others Like Google Chrome, Microsoft Edge, Opera, etc. should be verified as similar:


We get some errors on the browser console saying there's no internet connection, which we intended to do.
This is where a mock server can help us developers stay productive by giving us a way to mock our data requirements in order for us to keep developing the component UI first and deal with this sort of scenario afterward.
Install MSW
npm install msw@^0.36.0 --save-dev
npx msw init public/ --saveThis will install the MSW package as a dev dependency on the project, and then it will copy over a service worker file called mockServiceWorker.js to the public folder on the root of the repository.
Notice that we install a specific version of MSW to be 100% compatible with the rest of the tutorial.
Mocking external API
To define which requests should be mocked, we will use request handler (opens in a new tab) functions. They allow us to capture any request based on its method, URL, or other criteria and specify which response to return.
mkdir src/mocks
touch src/mocks/handlers.tsThe handlers from this module can be reused for both browser and Node in the further steps of this tutorial.
import { rest } from 'msw'
export const handlers = [
rest.get('https://jsonplaceholder.typicode.com/users', (req, res, ctx) => {
return res(
ctx.delay(),
ctx.status(200),
ctx.json([
{ id: 1, name: 'Leanne Graham' },
{ id: 2, name: 'Ervin Howell' },
{ id: 3, name: 'Clementine Bauch' },
{ id: 4, name: 'Patricia Lebsack' },
{ id: 5, name: 'Chelsey Dietrich' },
{ id: 6, name: 'Mrs. Dennis Schulist' },
{ id: 7, name: 'Kurtis Weissnat' },
{ id: 8, name: 'Nicholas Runolfsdottir V' },
{ id: 9, name: 'Glenna Reichert' },
{ id: 10, name: 'Clementina DuBuque' },
])
)
}),
]Now that we have a mock for the JSONPlaceholders API users endpoint, we need a way to use it inside the Storybook environment.
Setup MSW for Storybook
We can now set up our Storybook environment to initialize MSW on page load. To integrate MSW into Storybook, a package called msw-storybook-addon makes this process a breeze.
Letās start by installing the package itself:
npm install msw-storybook-addon --save-devWe can now configure Storybook with the package installed to initialize the service worker when loading Stories. Letās update the .storybook/preview.js file to look something like:
import { initialize, mswDecorator } from 'msw-storybook-addon'
import { handlers } from '../src/mocks/handlers'
import '../src/index.css'
initialize({ onUnhandledRequest: 'bypass' });
export const decorators = [mswDecorator];
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
msw: { handlers },
}We added the import statements for the msw-storybook-addon package as well for the MSW handlers variables that we created in the previous step.
We start the service worker on line 5 and pass the configuration option onUnhandledRequest with the value bypass, so we don't have warnings on the console regarding HTTP requests not being handled by MSW.
On line 7, we define a global decorator that integrates seamlessly with our Story files for when we want to configure specific MSW handlers for specific stories.
Last but not least, on line 17, we configure our global handlers. This way, we donāt need to add the handlers to a specific story, as it will be loaded automatically.
We need to do one more thing before testing our mocks in Storybook. We talked about a service worker being initialized, but where is this service worker code available? The service worker file was generated into the public folder from the step where we installed the MSW package.
Assets in this directory will be served by Vite at the root path / during development and copied to the root of the dist directory as-is when building. To get the same behavior on Storybook, we need to update the .storybook/main.js file to serve the public folder assets as static files as well:
module.exports = {
"stories": [
"../src/**/*.stories.mdx",
"../src/**/*.stories.@(js|jsx|ts|tsx)"
],
"addons": [
"@storybook/addon-links",
"@storybook/addon-essentials"
],
"core": {
"builder": "storybook-builder-vite"
},
"staticDirs": ["../public"], // this line was added
}Now we can restart our Storybook development server and check if the MSW is being initialized correctly:
npm run storybook
After opening the Storybook on the browser and checking the console, we can see a log message saying [MSW] Mocking enabled. which means our MSW setup for Storybook was successful. You can also see another log right after with a message like [MSW] GET https://jsonplaceholder.typicode.com/users (opens in a new tab) (200 OK) that tells us a request to the https://jsonplaceholder.typicode.com/users (opens in a new tab) URL was intercepted correctly.
This is exactly the result we were expecting, but so far, everything is working as it was before installing and setup MSW. Itās time to test the scenario that we tested before, where we switched the network condition to offline on the developer tools:

As you can see on the screenshot above, even after forcing the browser to be offline š, the mock server still works, and the Users component still gets the usersā data that we configured on the handlers file.
This is a big deal as developers can mock our data requirements and keep developing components in total isolation.
Also, remember the issue we talked previously about when we tried to deploy our design system, and then the mock server wasnāt available? This issue is now gone because the mock server powered by MSW will be bundled when we build the Storybook project. This means that when we deploy the Storybook statically built assets, MSW will also be a part of it, and it will work the same way it does when developing locally.
Letās test this by building our Storybook project first:
npm run build-storybookNow there is a storybook-static folder on the root of the repository that can be served with any static HTTP server; for this example, we will use the http-server (opens in a new tab) package:
npx http-server ./storybook-static/This will start a static HTTP server serving our Storybook-built assets. Now we can visit http://localhost:8080 (opens in a new tab) to view our stories.

Everythingās working exactly the way it did when running with the development server! One last test just for good measure ā letās set the browserās network to be offline and see if we still get the mock data users to be rendered on the Users component.

And with no surprise, it still works. š
Before continuing with the tutorials, let's update the .gitignore file to ignore the storybook-static folder, so we donāt accidentally commit generated files to our repository
node_modules
.DS_Store
dist
dist-ssr
*.local
storybook-static # this line as addedSetup MSW for the development environment
With our Storybook environment being 100% to be used with MSW, itās time to move on to the front-end development server.
We already did a couple of steps required to use MSW with our development environment. One being installing MSW and the other being adding the request handlers. With these both out of the way, we need to initialize the MSW service worker when we load pages with our development server.
To initialize the MSW service worker, we need to configure the worker following this documentation (opens in a new tab). Let's create a file in our mocks directory (src/mocks) where we would configure and start our service worker.
touch src/mocks/browser.tsIn the browser.ts file, we are going to create a worker instance with our request handlers defined earlier.
import { setupWorker } from 'msw'
import { handlers } from './handlers'
export const worker = setupWorker(...handlers)āFor our mocks to execute during the runtime, it needs to be imported into our application's code. However, since mocking is a development-oriented technique, we will be importing our src/mocks/browser.ts file conditionally, depending on the current environment.
It's not recommended to include Mock Service Worker in production. Doing so may lead to a distorted experience for your users.
Import the src/mocks/browser.ts file conditionally on the src/main.tsx file:
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import { App } from './App'
async function prepare() {
if (process.env.NODE_ENV === 'development') {
const { worker } = await import('./mocks/browser')
return worker.start({ onUnhandledRequest: 'bypass' })
}
return Promise.resolve()
}
prepare()
.then(() => {
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
)
})
.catch(console.error)The prepare function was added to import the browser.ts file dynamically only when we are in development mode.
We can now run the development server and see if the MSW service worker gets initialized properly:
npm run dev
After opening http://localhost:3000 (opens in a new tab) on the browser and checking the console, we should see a log with [MSW] Mocking enabled. just like we saw when we set up MSW for Storybook.
With our mock server ready to be used on the development server, letās import the Users component and render it on the page by updating the src/App.tsx file:
import logo from './logo.svg'
import { Users } from './components/users'
import './App.css'
export const App: React.FC = () => {
return (
<div className="app">
<header className="app-header">
<img src={logo} className="app-logo" alt="logo" />
<p>Hello Vite + React!</p>
<Users />
</header>
</div>
)
}
As you can see, the request handler for the https://jsonplaceholder.typicode.com/users (opens in a new tab) endpoint was called successfully. š
The MSW is now ready to mock any network request you need!
Setup MSW for the Jest environment
Our project has a couple of test environments configured, one being Jest and the other being Cypress. It would be awesome to use MSW on these environments as well.
Previously we set up MSW to run on Storybook and development server, which are both browser environments, but Jest is a Node environment. Thankfully, MSW handlers can be used on both browsers and Node environments!
To integrate MSW handlers into a Node environment, we need to configure a server for it first. Let's create a file in our mock definition directory (src/mocks) where we would configure our request mocking server:
touch src/mocks/server.tsIn the server.ts file, we will create a server instance with our request handlers defined earlier.
import { setupServer } from 'msw/node'
import { handlers } from './handlers'
export const server = setupServer(...handlers)āWith our mock server ready for Node environments, we can start to integrate with our Jest configuration.
We can create a custom setup module and reference it using Jest's setupFilesAfterEnv (opens in a new tab) option in your jest.config.js file. Letās create a jest.setup.js test setup file:
touch jest.setup.jsconst { server } = require('./src/mocks/server')
// Establish API mocking before all tests.
beforeAll(() => server.listen())
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => server.close())Now we need to reference this test setup file in the jest.config.js file:
module.exports = {
preset: 'ts-jest',
testMatch: ['**/src/**/?(*.)+(spec|test).[jt]s?(x)'],
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
'\\.(css|less|scss|sass)$': 'identity-obj-proxy',
},
testEnvironment: 'jest-environment-jsdom',
setupFilesAfterEnv: ['./jest.setup.js'], // this line was added
}Letās try running the tests and see if every still works:
npm run testWe get an error when executing the renders hello message test:
ā renders hello message
ReferenceError: fetch is not defined
10 |
11 | useEffect(() => {
> 12 | fetch('https://jsonplaceholder.typicode.com/users')
| ^
13 | .then((res) => res.json())
14 | .then((result: User[]) => {
15 | setUsers(result)
at src/components/users.tsx:12:5
at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20)
at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)
at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:338:25)
at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:274:3)
at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:221:9)
at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:231:34)
at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16)
at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31)
at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9)
at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12)
at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10)
at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14)
at Object.<anonymous>.flushWork (node_modules/react-dom/cjs/react-dom-test-utils.development.js:992:10)
at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1107:9)
at render (node_modules/@testing-library/react/dist/pure.js:97:26)
at Object.<anonymous> (src/App.test.tsx:6:9)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 2.175 s, estimated 3 s
Ran all test suites.The specific error message is ReferenceError: fetch is not defined, telling us the Fetch API isnāt available on the Jest Node environment. We can fix this by importing a polyfill for it. For this tutorial, we are going to use the whatwg-fetch package:
/co
npm install whatwg-fetch --save-devNow letās import this polyfill into the jest.setup.js file created earlier:
require('whatwg-fetch') // this line was added
const { server } = require('./src/mocks/server')
// Establish API mocking before all tests.
beforeAll(() => server.listen())
// Reset any request handlers that we may add during the tests,
// so they don't affect other tests.
afterEach(() => server.resetHandlers())
// Clean up after the tests are finished.
afterAll(() => server.close())Letās rerun our tests:
ā
npm run test> [email protected] test
> jest
PASS src/demo.test.ts
PASS src/App.test.tsx
Test Suites: 2 passed, 2 total
Tests: 2 passed, 2 total
Snapshots: 0 total
Time: 1.856 s, estimated 3 s
Ran all test suites.Our tests run successfully again!
We should now assess that our mock server is indeed working by making some assertions on the App.spec.tsx file. Let's assert that the header with the text Users is being rendered and the usersā list with all 10 items being mocked by the MSW.
import '@testing-library/jest-dom'
import { render, screen } from '@testing-library/react'
import { App } from './App'
it('renders hello message', () => {
render(<App />)
expect(screen.getByText('Hello Vite + React!')).toBeInTheDocument()
expect(
screen.getByRole('heading', { level: 1, name: 'Users' })
).toBeInTheDocument()
expect(screen.getByRole('list')).toBeInTheDocument()
expect(screen.getAllByRole('listitem')).toHaveLength(10)
})Letās run the tests again and see if all assertions are true:
npm run testWe get the following error on the App.spec.tsx test file:
Unable to find an accessible element with the role "listitem"It's telling us that there are no <li> items being rendered when this assertion occurs. This happens because we only render our users list when we have users on the users state variable inside the React component. We make the HTTP request to fetch the users, which takes time to resolve. This is called an asynchronous task, so in sort, we are trying to assert the users' list being rendered before we even have the data (still loading) available to render the UI.
To make our tests more resilient, letās update our Users component first to have it render a loading state until the usersā data is loaded successfully:
// ...
export const Users: React.FC = () => {
const [isLoading, setIsLoading] = useState(false) // this line was added
const [users, setUsers] = useState<User[]>([])
useEffect(() => {
setIsLoading(true) // this line was added
fetch('https://jsonplaceholder.typicode.com/users')
.then((res) => res.json())
.then((result: User[]) => {
setUsers(result)
})
.catch(console.error)
.finally(() => {
setIsLoading(false) // this line was added
})
}, [])
return (
<div>
<h1>Users</h1>
{/* we conditionally render the loading or success UI */}
{isLoading ? (
<div>Loading...</div>
) : (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
)}
</div>
)
}Letās update the test file as well to assert on the loading state, and when the loading state is not present anymore, we assert on the usersā list being rendered:
import '@testing-library/jest-dom'
import {
render,
screen,
waitForElementToBeRemoved, // this line was added
} from '@testing-library/react'
import { App } from './App'
it('renders hello message', async () => { // this line was updated
render(<App />)
expect(screen.getByText('Hello Vite + React!')).toBeInTheDocument()
expect(
screen.getByRole('heading', { level: 1, name: 'Users' })
).toBeInTheDocument()
const loading = screen.getByText('Loading...') // this line was added
await waitForElementToBeRemoved(loading) // this line was added
expect(screen.getByRole('list')).toBeInTheDocument()
expect(screen.getAllByRole('listitem')).toHaveLength(10)
})Setup MSW for the Cypress environment
Before we continue with the configuration of MSW for the Cypress environment, letās update both Vite and Cypress to have the latest and greatest available for us to use:
npm update vite cypressThis command updates Vite and Cypress to their current latest versions.
In the How to set up a front-end project with Vite, React, and TypeScript blog post (opens in a new tab), we used the Vite development server for running our Cypress tests against. A better approach would be for us to run the production version of our application when running E2E tests.
To run the production version of our application, we first need to build it by running the build command:
npm run buildAfter our application is built, we can serve it via the serve NPM script:
npm run serveThis starts a server with our previously built assets from the build command.
⯠npm run serve
> [email protected] serve
> vite preview
> Local: http://localhost:4173/
> Network: use `--host` to exposeNotice anything different on the URL where the production version of our project is being served? The port is now 4173 instead of 3000, like when we started the development server.
We can configure Vite to use the same port for both development and production by updating the vite.config.js file:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
preview: { port: 3000 }, // this line was added
server: { port: 3000 }, // this line was added
})Notice the preview and server configuration options added where the port is the same.
Letās run the serve script again:
npm run serve⯠npm run serve
> [email protected] serve
> vite preview
> Local: http://localhost:3000/
> Network: use `--host` to exposeOur production server is now running on port 3000 as well. This way, we donāt need to change our Cypress test URLs.
To seamlessly integrate MSW with Cypress, we need to make sure it plays well with the Cypress intercept (opens in a new tab) API. This API enables us to spy and stub network requests and responses.
We can use a package called cypress-msw-interceptor to help us with the setup. This plugin takes the features of MSW and adapts its API to work with Cypress in a way that cy.intercept works. This plugin will start an MSW worker as part of the Cypress runner and intercept fetch requests from the tested application.
Letās start by installing the plugin package:
npm install cypress-msw-interceptor --save-devWith the plugin installed, its time to import it on the cypress/support/index.ts file:
import './commands'
import 'cypress-msw-interceptor' // this line was addedLetās update the integration test file:
describe('App', () => {
it('shows the users list', () => {
cy.interceptRequest(
'GET',
'https://jsonplaceholder.typicode.com/users',
(req, res, ctx) => {
return res(
ctx.delay(),
ctx.status(200),
ctx.json([
{ id: 1, name: 'Mock User 1' },
{ id: 2, name: 'Mock User 2' },
{ id: 3, name: 'Mock User 3' },
]),
)
},
)
cy.visit('/')
cy.findByRole('heading').should('have.text', 'Users')
cy.findByText('Loading...').should('exist')
cy.findByRole('list').should('exist')
cy.findAllByRole('listitem').should('have.length', 3)
})
})Some errors are being reported by TypeScript, saying that Property 'interceptRequest' does not exist on type 'cy & EventEmitter.ā The method, in fact, exists, but as far as TypeScript is aware, itās not. To fix this, we can extend the TypeScript declarations for the cy global variable:
import { rest } from 'msw' // this line was added
import './commands'
import 'cypress-msw-interceptor'
// this block was added
declare global {
namespace Cypress {
interface Chainable {
interceptRequest(
method: string,
url: string,
responseResolver: Parameters<typeof rest.get>[1],
alias?: string,
): Chainable<any>
}
}
}Letās run the E2E tests now:
npm run cypress:open
Click on the app.spec.ts integration test to start running it.

The Cypress test is now updated to mock the HTTP request to the JSONPlaceholder API, and you can see on the image above a list of users with the mock data that we added to the app.spec.ts file.
Both Cypress and MSW are amazing technologies; this plugin takes the features of MSW and adapts its API to work with Cypress in a way that cy.route works.
Conclusion
In many projects, waiting for the API is just not an option. And thatās why Mock Service Worker is the perfect match for all the times you need to request data from external resources. Mocks give you a seamless experience that improves your development workflow, as weāve seen in the different strategies explored in this tutorial.
References
Written by

Rui Saraiva
Principal Engineer