Questions tagged [msw]
Mock Service Worker is an API mocking library that uses Service Worker API to intercept actual requests.
213
questions
0
votes
0
answers
9
views
MSW to mock a streaming API results in TypeError: Invalid state: The ReadableStream is locked
I'm trying to intercept and mock an API which returns a stream.
The test setup -
import { setupServer } from "msw/node";
const restHandlers = [
http.post(`/path/to/my/api?jwt=jwt`, async (...
-1
votes
0
answers
19
views
Only the react-query test code does not run in Jest 29.7 with MSW 2.3.1
Currently, Jest is using version 29.7 and MSW is using version 2.3.1.
When I set up MSW and wrote test code for React queries, it kept failing.
However, if I create a random fetchMock and run the test,...
0
votes
0
answers
54
views
Facing the issue where FormData is not being retrieved in MSW, possibly due to an async/await problem?
I am writing one test case to test my component which on upload calls this api, this api could return 2 responses i.e failure or success. I want to test both conditions based on filename coming in ...
0
votes
1
answer
113
views
how to solve the script has an unsupported MIME type ('text/html')?
I get this: Service Worker URL: /mockServiceWorker.js index.tsx:33
Failed to start mock service worker: DOMException: Failed to update a
ServiceWorker for scope ('http://localhost:3000/') with script
(...
0
votes
0
answers
26
views
my project failed to register the Service Worker while adopting mocks with MSW on local and ghpages, any clues?
My folder structure:
I have these mocks:
import { http, HttpResponse, delay } from "msw";
import { Image } from "../models/image";
import { API_URL } from "../constants/...
1
vote
0
answers
68
views
Test suite failed to run ReferenceError: TextEncoder is not defined
I am trying to test my project using a mock API instead of a real one to save money. However, when I add the following code to my setupTests.js file:
// setupTests.js
import { server } from "./...
1
vote
0
answers
42
views
Mock a different response for identical API calls that only differ on payload
I have a Lit component that makes two AJAX calls to an external API:
1
Endpoint: PUT /api/rest/books/
Payload: { view: "VIEW_1", properties: { a: "abcde" } }
Desired response: a ...
0
votes
0
answers
67
views
Redux state not updating during testing after MSW mock request
I'm adding integration tests to key components in my app and I'm having trouble getting things to work as expected between Jest, RTL, Redux (RTK) and MSW. I have set up my environment with the ...
-1
votes
1
answer
143
views
Jest-environment-jsdom not working with MSW
I have a custom Webpack setup with type: module and TS. Everything works fine until I try to run tests having Mock Service Worker "integrated".
I have this folder structure
├── mocks/
│ ├──...
0
votes
1
answer
61
views
WxWidgets - Error in build with mingw32-exe dll, mingw64
I am trying to build WxWidgets 3.2.4 with MinGW64 g++ from the cmd line.
After downloading the source, I followed the build instructions ("...\docs\mswinstall.md"), which state:
### Using ...
0
votes
1
answer
65
views
Create React App & Jest, unable to make API calls in test files
I made a simple create-react-app, and just trying to call an API in the test case. The api call is actually made, but nothing will be run in the .then function.
The reason I'm trying to figure this ...
3
votes
1
answer
720
views
MSW - Error: No known conditions for "./browser" specifier in "msw" package
After doing successful MSW (Mock Service worker) setup for browser. Everything is working fine.
Here is my setup files ->
//handlers.ts
import { http, HttpResponse } from 'msw';
const handlers = [
...
0
votes
0
answers
17
views
React-testing-library fetches XML data and allows user to continue
trying to do testing for the Post API call wherein the response is xml data. And also trying to achieve the passing of the test case
below is the code to resolve
describe('CardDesignTestPage', () =&...
0
votes
1
answer
188
views
The Service Worker does not shut down
I'm using msw to mock API request, and almost API develop is done, so I want to turn off serviceworker and I turn on / turn off bypass for network in developer mode's application tab
but still msw is ...
0
votes
1
answer
192
views
React-Testing Library and MSW v2 renderHook returns no data on RTKQ
I have set up a test so that I can test a RTKQ to return a simple json back. I get the IsSuccess true but data us undefined. Can see it go from isLoading to is Success so the call is being observed to ...