Questions tagged [msw]

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

184 questions
0
votes
0 answers

Custom react-testing-library test setup causes tests to hang indefinitely on API calls

I'm using Jest to do some integration testing on my React App (AWS, Redux Toolkit, MSW). I have a custom setup files that I am using in my tests as per react-testing-library instructions…
ichiin
  • 1
0
votes
0 answers

Mock API calls using Mock Service Worker, with environment variables

I am using Mock Service Worker (MSW), in my Vite React app which is working fine when the handler paths were hardcoded and my handler URL matched my fetch URL. But as the project is progressing, we now have different APIs for development and…
Harry
  • 1
  • 1
0
votes
0 answers

reducer not getting called after dispatch when using mock service worker

reducer not getting called on dispatch in - redux + thunk + react testing library + MSW all details in https://github.com/reduxjs/react-redux/issues/1975 after dispatch reducer should get called and i should be ale to assert the mocked data returned…
0
votes
1 answer

Intercepting Auth0 getSession with MSW.js and Cypress

I'm building NextJS app with SSR. I've written the getServerSideProps function that makes a call to supabase. Before making the call I'm trying to get user session by calling getSession function from @auth0/nextjs-auth0 package. I'm trying to mock…
0
votes
0 answers

How to wait for all requests in jest tests using MSW

I've just started using MSW (https://mswjs.io/) in the tests. I came however across a case that I have no clue how to deal with. Let's say we are testing component A (render in a test) which makes three different API requests. All of them are…
Marcin
  • 770
  • 6
  • 12
0
votes
0 answers

mock-service-worker test GET and PUT in same test

I'm using react-query with react-testing-library and msw (mock-service-worker). Is this a correct way mock both a GET request called from a useQuery hook when the component renders, and PUT request when the form is submitted, in one test block?…
Duderino9000
  • 2,535
  • 4
  • 31
  • 37
0
votes
0 answers

How to use msw (mocking service worker) with React typescript?

I have installed msw using package.json entry in my react typescript project. And appropriately invoking msw worker start but I constantly get the error **getWorkerInstance.ts:85 Uncaught (in promise) Error: [MSW] Failed to register the Service…
Ankit S
  • 9
  • 3
0
votes
0 answers

no such file or directory, open mockServiceWorker.js

i'm a beginner in Node.js and i dont understand what is this **/mockServiceWorker.js **file? The problem is that my req.url is changing to /mockServiceWorker.js after some time, even though the first couple of seconds everything is working fine and…
0
votes
1 answer

Test Mocking with SWR - waitForElementToBeRemoved timed out

I am trying to setup some tests for my project, and I'm having some trouble with dealing with asynchronous components which rely on useSWR. My test file looks like this: import { render, screen, waitForElementToBeRemoved, act, } from…
0
votes
0 answers

Compile error using MSW with web test runner / rollup

I want to use MSW with rollup and web test runner. As soon as I import setupServer and run the test the following error is thrown: Could not import your test module. Check the browser logs or open the browser in debug mode for more…
0
votes
0 answers

Vitest + MSW - Runtime request handler is not working

I'm trying to migrate the test framework of my app from Jest to Vitest (for multiple reasons) and I encounter an issue. With Jest, I was using runtime request handlers at multiple places of my app to control that I have the correct behavior/output…
0
votes
0 answers

Nodejs server - how can I intercept a 3rd party request and forward it the request to a proxy (rewrite request)?

Scenario I have nodejs app is deployed on our infrastructure at work At some point in the login / auth process of my app, my app will make a POST request to https://login.microsoftonline.com for authenticating the user (remix-auth-microsoft library…
Clifford Fajardo
  • 1,357
  • 1
  • 17
  • 28
0
votes
0 answers

RTK Query Error: 'AbortError: Aborted' while running test

I'm trying to run a test on login form submit which goes through a Rest API call to authenticate a user. I have configured MSW for mocking the rest API. Whenever I am running the npm test command the rest api call isn't going through and returning…
Nitish Anand
  • 143
  • 1
  • 9
0
votes
1 answer

vitest + msw / testing reactQuery (axios) hooks using renderHook / unable to avoid error logging from test suite

Using a custom logger as follow for our test suite : export const queryClient = new QueryClient({ logger: { log: console.log, warn: console.warn, error: () => {} } }); Mocking errors as follow within msw…
Ben
  • 5,030
  • 6
  • 53
  • 94
0
votes
1 answer

HTTP interceptors (nock, msw) not working in Github Actions but work locally

I've tried a basic API test using two different libs - nock and msw - and both of them work locally. However, when running in Github Actions, they both fail with the same error: nock: FAIL src/CustomHeader.test.ts ● Test suite failed to run …
Juha Untinen
  • 1,806
  • 1
  • 24
  • 40