Questions tagged [msw]

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

184 questions
1
vote
1 answer

MSW: Failed to register a ServiceWorker for scope with script The script has an unsupported MIME type ('text/html')

I am working on a react app using MSW. Everything was cool until I deployed my app to Github pages. This is an error I get: Uncaught (in promise) Error: [MSW] Failed to register a Service Worker for scope ('https://myprofile.github.io/') with script…
TeodorWolski
  • 31
  • 3
  • 6
1
vote
0 answers

Updating create-react-app to latest version breaks async tests

I have an issue, I have recently upgraded my version of react to use react-script version 5.0.1 from version 4.0.3. Doing the instructions as per https://github.com/facebook/create-react-app/blob/main/CHANGELOG.md Upon doing this. I can see it had…
Sole
  • 3,100
  • 14
  • 58
  • 112
1
vote
0 answers

How can I test the custom fetch hook with dummy data?

I have a custom fetch hook. It is not doing a real fetch process. It's an implantation example. I want to write a proper test for it. This is the pseudo API. import { data } from './data'; import { IProduct } from '../common/types'; // pseudo…
1
vote
0 answers

msw: graphql operation doesn't get intercepted

Using MWS, I'm trying to mock the graphql operation testRequest as follows: Funny thing is, the console.log in the graphql.query('testRequest', (_, res, ctx)=> {...}) block never gets invoked while the operation name is valid. What could be the…
lomse
  • 4,045
  • 6
  • 47
  • 68
1
vote
0 answers

Getting auth token using MSW| React-Redux-Test

I'm trying to login using the msw library and following the Redux docs. Then I want to get the user auth token. I'm sending request for login but idk how to get auth token if logged in. Is the structure in the example correct for login? If not, how…
hsngdr
  • 21
  • 5
1
vote
0 answers

Tests haphazardly fail when using graphql-request and MSW

I am trying to set up tests to test a Remix loader and noticed that the request function from graphql-request haphazardly fails when using MSW. If I replace this and use a simple fetch for the requests the tests pass. Is there any configuration I…
Charklewis
  • 4,427
  • 4
  • 31
  • 69
1
vote
1 answer

Problem unit testing a delete method with mock service worker (MSW), node and React

I have MSW setup with React and Typescript, the code works in the browser, ie, it deletes the employee, but not in the test, the other tests are working fine. I'm stumped, there's probably something daft that I'm doing, any help would be greatly…
1
vote
1 answer

Can someone compare SinonJS to Mock Service Worker MSW

Can someone compare and contrast SinonJS to Mock Service Worker MSW? Something similar to https://mswjs.io/docs/comparison
1
vote
1 answer

Testing createAsyncThunk with Mock Service Worker Fails

I am new to the redux-toolkit and its testing. I am trying to write a test for a createAsyncThunk that calls an API and updates the state by the data from the API. My async thunk is being called by a button in my component and rather than testing…
Ali Raza
  • 73
  • 1
  • 9
1
vote
1 answer

How to fix the Jest Test using Mock Service Worker?

I want to test the React App function import React from 'react' import { useState, useEffect } from "react"; function App () { const [message, setMessage] = useState('') useEffect(() => { async function getMessage ()…
stein korsveien
  • 1,047
  • 5
  • 13
  • 35
1
vote
2 answers

Test failing case with React, Jest, React-Testing-Library

For this test case, I am testing a form to see if an error message appears in the DOM after the form is submitted and the response from the server returns with an error. I am using 'MSW' (Mocked Service Worker JS) to mock out the API requests and…
1
vote
0 answers

Mocking GraphQL API with MSW for Testing

I'm trying to mock graphql API for testing react app but facing a problem the handler is: import { graphql } from 'msw' export const postsGql = [ { userId: 1, id: 1, title: 'first post title', body: 'first post body', }, …
1
vote
0 answers

Import not found: getCleanUrl

I try to use MSW with '@web/dev-server' and always get a Uncaught SyntaxError: import not found: getCleanUrl coming form http://localhost:8000/node_modules/msw/lib/esm/RequestHandler-deps.js The most minimal example I can come up is:
michaPau
  • 1,598
  • 18
  • 24
1
vote
1 answer

@mswjs/data question: why does RTK-Query sandbox example need separately handcoded POST and PUT mocks?

This is a question about the default behaviour of @mswjs/data.toHandlers function using this example with @mswjs/data to create mocks for RTK-Query…
Laurence Fass
  • 1,614
  • 3
  • 21
  • 43
1
vote
1 answer

How to mock an external domain/resource using mswjs?

I'd like to use mswjs to mock some external APIs (not on localhost), I can't find any information online on wether this is possible or not. I need to mock both localhost resources and external resources at the same time. May someone provide an…
Fez Vrasta
  • 14,110
  • 21
  • 98
  • 160