Questions tagged [msw]

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

184 questions
3
votes
1 answer

How do I suppress expected Axios error messages when testing error states with react-testing-library?

I'm working on adapting some React code of mine to use @testing-library/react, react-query, and msw to mock network calls that I make using axios. So far (after some brainbending) I've got it working with this code! (yay!) The test in question…
rosalindwills
  • 1,382
  • 13
  • 23
3
votes
1 answer

How to match a buffer request body with Mock Service Worker

I am currently using Nock and would like to replace it with Mock Service Worker. With Nock I am able to match the stringified request body with the provided buffer: const request = nock(hostname) .post('/api/instance',…
AmD
  • 399
  • 2
  • 12
2
votes
1 answer

Testing with jest and React Native Testing Library

I’m a newbie with testing I’m trying to get a grip on testing React Native with Expo, Jest and React Native Testing Library I wrote a simple screen that takes data from an API and writes the first element in the screen with a < Text > import {…
Rafael
  • 2,413
  • 4
  • 32
  • 54
2
votes
1 answer

Mount vue after a worker is ready

I am using msw.js as request mocking library. However, some requests are triggered on development before the msw web worker is ready. I can be sure of because the first requests fail. I retry them in the UI with the DevTools and it works as…
Lyokolux
  • 1,227
  • 2
  • 10
  • 34
2
votes
2 answers

RTK Query Testing Error with MSW and vitest

I'm trying to test a component in React that uses RTK Query + MSW + Vitest. It works fine on the browser but while testing RTK Query with vitest it throws this error: { status: 'FETCH_ERROR', error: 'TypeError: fetch failed' } I've setup a public…
Casuso
  • 39
  • 6
2
votes
1 answer

Mock Service Worker-Expected response resolver to return a mocked response Object but got undefined. The original response is going to be used instead

React Testing Using Mock service worker is returning undefined and then taking values from the actual API. As you can see from the image down below the test is getting passed by getting values from the actual API and the name ARLO WANG is getting…
2
votes
2 answers

How to use 'jsonwebtoken' library to generate a JWT token in Nuxt 3?

I'm using the mswjs library for mocking APIs in a Nuxt 3 (3.0.0-rc.11) project; Everything is working fine until I try to import the 'jsonwebtoken' library to generate a JWT access token to mock the login API call. Here is the login request…
mo3n
  • 1,522
  • 2
  • 10
  • 34
2
votes
2 answers

mock service worker not working with axios post and payload

I'm running into a weird problem. Mock Service Worker is not intercepting axios.post with a payload. Without the payload it works. For exmaple: This works: await axios.post(`${BASE_URL}/test.json`); This does not work: await…
Federico
  • 5,438
  • 5
  • 39
  • 47
2
votes
0 answers

how to mock a post request with MSW in jest

I am new to testing and am currently trying to test a form from my svelte app. On this form there is only one input for a category. When the backend receives this category a uuid is generated for it and a json object with the category and uuid is…
2
votes
1 answer

What must I do to get this Jest test with Mock Service Worker for React hook to work?

I want to use Jest and Mock Service Worker to test a React Hook with a fetch call The test look like this: import React from 'react' import App from './App' import {render,screen} from '@testing-library/react' import { rest } from 'msw' import {…
stein korsveien
  • 1,047
  • 5
  • 13
  • 35
2
votes
1 answer

react-testing-library and MSW

I have been trying to implement some tests on my project, but I got some blockers. This error: Unable to find an element with the text: C-3PO/i. This could be because the text is broken up by multiple elements. In this case, you can provide a…
KLuz
  • 21
  • 1
2
votes
1 answer

Using Mocked Service Worker (msw) with @web/test-runner

I am trying to setup msw with @web/test-runner (and playwright). The problem is that I don't know how the mockServiceWorker.js can be picked up by the test runner (which uses browser, not nodejs like jest). There is an example with…
Jinx
  • 348
  • 3
  • 14
2
votes
1 answer

how to pause the Mock Service Worker for testing the intermediate state, in react testing library?

I am using the MSW (Mock Service Worker) to mock the HTTP response in my react testing with react testing library. but, in some of the react components, I have some loading state until the response is fulfilled. to test the intermediate loading…
rahul Kushwaha
  • 2,395
  • 7
  • 32
  • 64
2
votes
1 answer

React/Jest/MSW Wait for response throws errors using act()

Currently, I'm learning how to unit test with React. However, I'd like to learn it with TypeScript, so the course does not cover most errors that occur with TS. I have a simple testing function configured with Mock Service Worker (msw): fit("sends…
Starfish
  • 3,344
  • 1
  • 19
  • 47
2
votes
1 answer

Service worker in a webpack module federation environment

I have a small setup with webpack module federation, one container app and one remote. The remote is exposing itself completely and the container is consuming it to show it after clicking a navigation link like /users. The container is reachable at…
koengsen
  • 25
  • 1
  • 5
1 2
3
12 13