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

React Query Test with MSW - renderHook result always returns null

I am trying to test my react query hook using msw but renderHook's result's current value is always null. Why? Note: the reason fetch does not include a URL is because this is a Rails Propshaft app and React and Rails apps share the same port. In…
asus
  • 1,427
  • 3
  • 25
  • 59
0
votes
0 answers

ECONNREFUSED while running tests on GitHub Actions pipeline via msw

I'm currently having react project which contains some unit, integrations tests. I'm using msw for mocking data and hosting mock handlers. It works without any issue on local. Problem: I'm having testing step in my GitHub Actions pipeline, not…
rufatZZ
  • 743
  • 2
  • 11
  • 27
0
votes
0 answers

MSW and Remix: globalThis.XMLHttpRequest is not a constructor

I've tried setting up MSW in my Remix app by copying a few examples (This playwright one and the remix-run example), but every time I get this error: [mf:err] TypeError: globalThis.XMLHttpRequest is not a constructor at checkTypeSupport…
Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
0
votes
1 answer

MSW doesn't catch Stripe requests

I'm trying to use MSW to mock my server side calls to Stripe in my integration tests. The code is pretty straight forward: // @vitest-environment node import { rest } from 'msw'; import { setupServer } from 'msw/node'; import { describe, expect,…
J. Hesters
  • 13,117
  • 31
  • 133
  • 249
0
votes
0 answers

Mock server worker is not intercepting get request

Goal I'm developing an React app (created with create-react-app). Currently I'm trying to test my component using react-testing library and Jest to ensure it shows the two elements below on visiting the dashboard of my app: a) loading spinner and…
mihomiho
  • 1
  • 2
0
votes
0 answers

MSW, blob size in multipart/form-data in request becomes 0

In one of my endpoints I need to add a multipart/form-data. the formData is created like so: // inputData is just an object: { info: 'something' } created by a form. // file is an image but irrelevant in this question const blob = new…
Henny Lee
  • 2,970
  • 3
  • 20
  • 37
0
votes
1 answer

Having issues with making tests work with RTK Query and MSW

I am trying to integrate MSW into testing for my Vite app with RTK Query and am having issues with the baseUrl TLDR: I want to make my RTK query base url /api instead of http://localhost:5173/api/auth but it is not working with MSW. Prior to adding…
0
votes
1 answer

How can I mock the onUploadProgress configuration for axios with Mock Service Worker?

I have a mock service worker (MSW), which intercepts any axios rest api request and mocks it. I have one specific api request to upload a file, it also has progress event, which tell me about the progress of the file being…
0
votes
1 answer

MSW does not intercept Api requests

i'm trying to make a mock service worker to a simple API request like that: /src/api/Sectors.js export const getSectors = async (token)=>{ const requestOptions = { method: "GET", headers: { "Content-Type":…
Wiskani
  • 9
  • 2
0
votes
1 answer

Testing fetch-policy of GQL query when using Mock Service Worker (MSW)

so I am using MSW to test my GQL and components, which means mocking Apollo will fail the tests. I want to test that the useQuery function is being called with the correct fetch-policy but it seems virtually impossible without having to mock Apollo…
narliecholler
  • 430
  • 5
  • 18
0
votes
0 answers

vite build bloating with assets not required

I have a vite app with react where i am using mui, aws amplify, MSW and other bits. much of this is used in production while rest not. e.g : MSW is not used in production aws amplify i am using only for auth. I would like the msw and graphql…
hafiz ali
  • 1,378
  • 1
  • 13
  • 33
0
votes
0 answers

How to test that function provided by context has been invoked inside a custom hook that is firing a network request using React Query Mutation

I am testing a custom hook called useRequest that's responsible for sending a particular request. It looks like this: export const useRequest = () => { const { updateContextState } = useSomeContext() const { isLoading, mutate, …
0
votes
0 answers

How to test a react form that uses RTK query?

I'm trying to test my App using react testing library and jest however the test cannot find the searched "robin" in the document. The BirdSearch.js component uses a redux slice and rtk query which I have set up a custom renderWithProviders as…
0
votes
0 answers

Is there a way to replace fake MSW data with a REST API in React?

I have created a working fake server for my React app using Mock Service Worker, or MSW. I find it troubling to replace the fake backend with my real Django REST API. Here is my fake backend index.js //import React from "react"; import {…
0
votes
0 answers

React testing library with mocha - mocking api call in test fails

I have a page that I want to test. These are the components that I am testing: export const Header = memo(() => { const { caseId } = useCase(); const { api } = useApiData(); const { data: { data: caseData }, } =…
Leff
  • 1,968
  • 24
  • 97
  • 201