Questions tagged [msw]

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

184 questions
1
vote
0 answers

Why the test is not checking the components which appears asynchronously?

I was trying to make a login page. In the server-side code, I added an express validator which will detect whether the email id is valid or not. In case it is not valid it will send an error message and upon receiving the error message an alert will…
Pawan
  • 459
  • 5
  • 17
1
vote
1 answer

Mock service worker on node post and grapql.query not working

I have a node app that uses a library to make a graphql query after it authenticated. The following graphql query does not pick up the request: graphql.query(/^(.+?)$/, (req, res, ctx) => { console.log('keys:', Object.keys(req)) …
HMR
  • 37,593
  • 24
  • 91
  • 160
1
vote
1 answer

react testing library with mock service worker should be able to dynamically return response

I have a form which i am trying to test and attached the sample test. In the form, it initially updates with get request. initially the checkbox https is not checked and thats asserted in the test with false. its assigned to variable button1 when…
hafiz ali
  • 1,378
  • 1
  • 13
  • 33
1
vote
0 answers

How to properly mock API results for testing with NextJS and MSW?

First of all, if I should ask this question elsewhere please let me know, as I'm not sure where it belongs. I have a working application with NextJS and MSW, where I can capture the server-side API requests with MSW and return mocked JSON…
Tyler
  • 1,163
  • 16
  • 37
1
vote
0 answers

Handler does not get call in MSW test

I'm trying to set up MSW. I have done all the steps. First I created a handlers.ts file like this: import { rest } from 'msw'; import { mockCharacters } from './mockData'; export const handlers = [ …
ludinj
  • 107
  • 7
1
vote
1 answer

How to retrieve data from msw mock request body

I am trying to retrieve data from a mock api call using msw while using Typescript. How would I go about doing this? I keep receiving "Property 'email' does not exist on type 'DefaultBodyType'" Handler export const handlers: RestHandler[] = [ …
kofi boateng
  • 95
  • 3
  • 9
1
vote
1 answer

connect ECONNREFUSED when using msw with react-testing-library (NextJS + SWR)

I'm struggling mocking the SWR fetch api call with MSW. You can reproduce the issue with this repo: https://github.com/charitha95/msw-test Error that I'm facing when using MSW: Error: connect ECONNREFUSED 127.0.0.1:80 at Object.dispatchError My…
Charitha Goonewardena
  • 4,418
  • 2
  • 36
  • 38
1
vote
0 answers

Error when I add msw init code in Next.js

I got this message when I init msw for mock api. node_modules\@cspotcode\source-map-support\source-map-support.js:153 while (match = re.exec(fileData)) lastMatch = match; ^ RangeError: Maximum call stack size exceeded at…
woocheol
  • 87
  • 1
  • 8
1
vote
2 answers

Getting response body of mock service worker

I am trying to use mock service worker to intercept a response from an endpoint and then modify one field of that json response. If we have an endpoint /user that returns a json looking like users: [{ user: { name: John, age: 31, …
1
vote
1 answer

Jest returns "Network Error" when doing a mock request with axios and msw

I have been using msw and axios to test my APIs in front end (node-typescript). The APIs return valid responses when I access them through Postman. The jest test for testing the GET API is server = setupServer(...mocks) server.use( …
agretsuko
  • 41
  • 1
  • 5
1
vote
1 answer

Bug with pipeline

I have some problem with my CI CD. Some days ago, library "headers-polyfill" was updated, and my new pipelines were failed. Earlier, before this update, I pushed branch into dev, and it was good. Now I have good pipeline in dev, and if I create…
DiMaS
  • 11
  • 2
1
vote
1 answer

While testing error responses, the test fails with the expected error (React/Jest/ReactQuery/Axios/MSW)

I am trying to test error states of the following MSW rest endpoint: import { rest } from 'msw' export const exceptionHandlers = [ rest.post(config.accountApiUrl + '/login', (req, res, ctx) => { return res( ctx.status(500), …
benmneb
  • 1,773
  • 1
  • 15
  • 26
1
vote
0 answers

React 18 MSW Codesandbox

I have my own sandbox template that I am trying to upgrade to react 18 but getting errors about an music directive location is undefined. Not sure what is missing https://codesandbox.io/s/react-typescript-w-mswjs-tailwindcss-wermmh Is it something…
jrock2004
  • 3,229
  • 5
  • 40
  • 73
1
vote
1 answer

Jest function fails to fire after network request in react component

Full Repo https://github.com/brianbancroft/sample-testing-msw-sb-jest-rtl Using mock service worker (msw) to respond to a network request, I have a React login component. On submit it sends a network request and on success it is supposed to trigger…
brianbancroft
  • 463
  • 3
  • 17
1
vote
0 answers

Type 'Recommendation[]' does not satisfy the constraint 'PathParams'. Index signature for type 'string' is missing in type 'Recommendation[]'.ts(2344)

I am building a app using react, typescript and msw. When I am adding types I got this error: Type 'Recommendation[]' does not satisfy the constraint 'PathParams'. Index signature for type 'string' is missing in type 'Recommendation[]'.ts(2344) my…