Questions tagged [msw]

Mock Service Worker is an API mocking library that uses Service Worker API to intercept actual requests.

184 questions
20
votes
2 answers

MSW logging warnings for unhandled Supertest requests

In my tests using Supertest and MSW I've noticed that, although they still pass successfully, MSW has started showing warnings for the requests that Supertest is making. For example (see files to reproduce at the end of the post): $ npm t >…
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
12
votes
3 answers

Typescript CRA with MSW: failed to parse source map

I have created a Create React App application with typescript template build in, then i installed MSW with npm and created files based on MSW install guide. It's working perfectly for jest, but for browser when im using start script i got a bunch of…
nero1141
  • 131
  • 1
  • 4
9
votes
1 answer

How do I mock server-side API calls in a Nextjs app?

I'm trying to figure out how to mock calls to the auth0 authentication backend when testing a next js app with React Testing Library. I'm using auth0/nextjs-auth0 to handle authentication. My intention is to use MSW to provide mocks for all API…
chidimo
  • 2,684
  • 3
  • 32
  • 47
8
votes
2 answers

Jest fails coverage reports with 'No element indexed'

I am running jest test suites for a Next.js app that uses Redux Toolkit. I'm using msw to mock any necessary calls to another api outside of the Next app that are handled by Redux Toolkit. I have not mocked ALL of the RTK query endpoints, only the…
Gurnzbot
  • 3,742
  • 7
  • 36
  • 55
5
votes
1 answer

msw not able to match the same request the second time with updated data in a single test

I have a simple list of homes generated with RTK query hooks where item can be marked favorite and data refetched automatically based on tags invalidation. While everything works when I run the project within the test msw is not able to match the…
user1751287
  • 491
  • 9
  • 26
5
votes
2 answers

HTTP Response with Content-Disposition doesn't trigger download

I use msw to mock backend responses for automated FE tests. I wanted to create an Export Functionality for user-created data. I am POSTing a Request to the desired route, and want to return a response with a .csv ; .pdf ; .xls file which should be…
D.Schaller
  • 611
  • 3
  • 19
5
votes
0 answers

Jest jsdom Protocol "http:" not supported

I am trying to run some integration tests for react using jest. When running the test, I get the following error UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:" . Initially I…
Adrian Pascu
  • 949
  • 5
  • 20
  • 48
4
votes
1 answer

How to use msw with Nextjs 13.2.1 (Error: Cannot access worker.start on the server.)

I'm integrating a mock API which basically send a response object with a set of messages that are supposed be shown in the UI(Chatbox) along with Username, user pic and so on. I'm having some trouble setting up the msw 1.1.0 with Next JS 13.2.1…
Mahijendra
  • 335
  • 5
  • 15
4
votes
0 answers

MSW Runtime request handler not working in Cypress (NextJs, Cypress, MSW)

I am using NextJs along with Cypress and MSW. I want to use the MSW worker in Cypress to flexibly mock responses for my api request along the test to have a common mocking tool for all types of tests. The MSW handlers in the worker setup (in NextJs)…
dnyn
  • 51
  • 4
4
votes
2 answers

MSW(Mock Service Worker) in Next js first render not working

I use msw with Next js. But at First render, cannot connect api this is index.tsx import { useQuery } from "@tanstack/react-query"; import axios from "axios"; const Home = () => { const getFruit = async () => { const { data } = await…
MR.Jeon
  • 85
  • 3
  • 12
4
votes
2 answers

Fetch never returns data when msw (Mock Service Worker) intercepts request

I am currently using next/jest to setup my environment, with msw and @testing@library/react. My test looks like: import { TestComponent } from '../../../components/TestComponent' import React from 'react' import { render } from…
Kalimantan
  • 702
  • 1
  • 9
  • 28
4
votes
2 answers

RTK Query invalidatesTags doesn't seem to remove cached data every time

I have an RTK Query mutation endpoint rejectApplication, that invalidates the getApplication query. These are in the same API. rejectApplication: builder.mutation({ query: (applicationId) => ({ url:…
niemelsa
  • 125
  • 2
  • 5
4
votes
1 answer

Getting request body of mock service worker and react testing library

So i am writing tests for one of my react projects and i just decided to use mock service worker to mock my api calls and i am trying to mock a login endpoint.So i am trying to simulate a login error where i return an error message when the input…
Patrick Obafemi
  • 908
  • 2
  • 20
  • 42
4
votes
1 answer

Mock service worker with openApi backend

I am working with MSW and OpenAPI-backend package. I want to mock the booth browser server and test server. I have OpenAPI definition available form with I generate generated.ts for RTK Query (out of scope for this question). I want to use OpenAPI…
4
votes
0 answers

how does whatwg-fetch work with msw/node?

I am using msw/node with my react-testing-library integration test. When we mock fetch api with msw/node, we have to use polyfills for that since node does not support browser specific api such as localstorage, fetch. msw documentation also states…
jwkoo
  • 2,393
  • 5
  • 22
  • 35
1
2 3
12 13