Questions tagged [msw]

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

184 questions
0
votes
1 answer

React MSW axios testing with jest doesnt't get triggered

I am trying to mock post request to api that returns status of 404, so after it returns response i can display an alert message which has data-testid="error-pw-api". But feels like the msw's post mock doesn't get triggered at all and it says can't…
eko
  • 329
  • 2
  • 11
0
votes
1 answer

How to set up Jest for API calls?

I'm trying to test my web page using MSW, jest, and react-testing-library. The app is built with NextJS and JS. I set up the MSW browser worker and everything goes fine, but when I tried to do the same with the node server throws an error. The error…
Rommel
  • 69
  • 1
  • 5
0
votes
1 answer

Mocked data included on production main.js file (Angular)

We noticed that all mocked data we added in our Angular app is included in the main.js bundle on production. All requests still fetch real data, though, so this is working fine, and this means we have configured MSW correctly. Does this happen by…
0
votes
2 answers

Cannot get response in msw while testing in react

I am trying to test a react app where it is fetching the data from jsonplaceholder. The fetch function is implemented in redux thunk via create async thunk. i followed every guide and every related answer on stackoverflow regarding this but got no…
0
votes
0 answers

Storybook re-renders story after receiving MSW response

When I trigger requests to the backend within a Storybook story, the story is re-rendered after receiving the response from Mock Service Worker (MSW). How can I prevent the re-rendering from happening? Here's the story: I followed the tutorial on…
davsto
  • 442
  • 5
  • 11
0
votes
1 answer

MSW cannot intercept requests when using testcafe as the page is outside of the workers scope

I have a React app which I am testing with Testcafe (with gherkin-testcafe). I am using MSW to mock API responses which works great. However the issue is when running testcafe tests against my local version running with MSW I get the following…
GaryB
  • 1
0
votes
1 answer

MSW v0.40 Error: thrown: Exceeded timeout of 5000 ms for a test

I've been using MSW since v0.35.0. Recently I updated it to v0.40.1 and now it seems like MSW is not intercepting the request to the servers and I'm getting the following error. Here is my test code. import axios from 'axios'; import { rest } from…
UK4
  • 460
  • 7
  • 25
0
votes
0 answers

Testing React app with Jest, Enzyme and Mock Service Worker (msw): How to mock API call?

I am testing my React app with Jest and Enzyme. For mocking an API call I use Mock Service Worker. My problem is, that I get an error with my current test code, saying "TypeError: Cannot read properties of undefined (reading 'company')". I will add…
Anne
  • 121
  • 1
  • 7
0
votes
1 answer

Failed to register the Service Worker: The operation is insecure

I'm having trouble using Mock Service Worker in a React project. The application is bundled using parceljs inside the dist folder, the pages are visualized correctly however msw is unable to register the service worker. I followed all the setup…
0
votes
0 answers

How to solve MSW random 404 error with React

I have started using MSW to mock the BE, but randomly it fails to fetch data when I save changes. Dont' really know how to debug it, since it's very random Api routing functions import Api from './Api'; export default class BrandsAPIs extends Api…
Andrea
  • 351
  • 1
  • 3
  • 9
0
votes
1 answer

Mock Service Worker returns empty

I'm new to react testing library. I am trying to test a simple component that call some apis and then it fills inputs with the data of these apis. But when I run npm test it keeps showing me this : the recieved value is empty Expected the element to…
hakima maarouf
  • 1,010
  • 1
  • 9
  • 26
0
votes
1 answer

MockServerWorker is not handling responses when using fetch in react

I'm doing test driven development in react course - I'm trying to development test for post request. Below is by react code. import React from "react"; import axios from "axios"; class SignUpPage extends React.Component { state = { } …
user51
  • 8,843
  • 21
  • 79
  • 158
0
votes
1 answer

AbortController not working in React test (Jest)

We have a function in our React project to fetch a list of stores. If the fetch takes longer than 3 seconds (set low for testing purposes) we abort the request and show an error. const controller = new AbortController(); const getTimeout =…
codemon
  • 1,456
  • 1
  • 14
  • 26
0
votes
1 answer

Error: connect ECONNREFUSED 127.0.0.1:80 if an axios fetch gets initialized outside of a react component react-testing-library/msw

I'm getting the ECONNREFUSED error and it looks like my msw server isn't catching my get request when I start a get outside of a React component (which shaves some time off of the response). When axios.get is uses inside of the useEffect everything…
Chloë Rice
  • 1
  • 1
  • 2
0
votes
0 answers

React Jest MSW server not running/working

Hello guys i have been stuck with this task for very long time and yet couldn't figure out after checking the docs and other resources in online. So i have this setup with Jest and MSW but i think the msw server not running at all. let url =…
eko
  • 329
  • 2
  • 11