Questions tagged [msw]

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

184 questions
0
votes
1 answer

response from "msw" handler stuck on "isLoading" after returning 404 code

I have the following test file: import { renderHook, waitFor } from '@testing-library/react'; import { QueryClient, QueryClientProvider } from 'react-query'; import { ReactPressProvider } from './ReactPressProvider'; import usePost from…
Enrique Moreno Tent
  • 24,127
  • 34
  • 104
  • 189
0
votes
1 answer

How does fetch detect if a request using a relative path is coming from a browser?

I am making a request from a react app using a relative path "/api/test". (an NGINX controller routes traffic to either the api or the react client, so they have the same base url) I found in the msw documentation that relative paths are…
BPDev
  • 397
  • 1
  • 9
0
votes
0 answers

Mock Service worker unhandled requests 'bypass' cookies are not attached to requests

I'm trying to integrate MSW into my next js project. The JWT tokens are set in cookies. Whenever any API arent mocked I want to bypass the request and send it to the server, but in my case, the request is sent without the cookies (HTTPOnly), hence…
Rahul
  • 462
  • 1
  • 4
  • 16
0
votes
0 answers

Break on unhandled request

I want MSW to break the test case when an request is not mocked. I've tried to modify onUnhandledRequest but with no success. Component: import React, { useState } from 'react'; import Child from './Child'; const ExampleComponent: React.FC = () =>…
Jedi Schmedi
  • 746
  • 10
  • 36
0
votes
0 answers

Is it possible to setup mswjs in Nuxt 3 for both client and server side

I'm trying to setup msw on my Nuxt 3 project. It's easy to setup for the browser but I'm stuck on setup for the server side. Does anyone have experience of this. Thank you!
itsncnt
  • 15
  • 4
0
votes
0 answers

How to test Nextjs App entire stack with msw

I have a Next app. I want to test E2E with mock apis (MSW), because I want fast tests that don't depend on third-parties to succeed. Let's imagine we have a stack like this : HomePage > click on Button > action.ts > axios.post('hostName/api/action')…
marcant0
  • 189
  • 8
0
votes
1 answer

Can't get body using msw and redux toolkit

This is my query: getMyQuery: builder.query({ query: (qParams) => ({ url: `url/endpoint`, method: 'POST', dataType: 'json', headers: { 'Content-Type':…
Dani
  • 3,128
  • 2
  • 43
  • 91
0
votes
0 answers

How to test login with typescript and MSW

I have and request component as follows: type HttpMethod = "GET" | "POST" | "PUT" | "DELETE"; type ApiCallOptions = { url: string; method?: HttpMethod; body?: T; headers?: Record; }; export async…
Boky
  • 11,554
  • 28
  • 93
  • 163
0
votes
1 answer

Once msw-storybook-addon added, I get Unexpected charachter '#' in node_modules/../Emitter.js

I want to use my mock servers for my stories. The Storybook runs perfectly. Once I go through the steps of adding msw-storybook-addon and set up my preview.js from here and here (preview.js is different in these two resources, I tried both), and I…
Andi Keikha
  • 1,246
  • 2
  • 16
  • 37
0
votes
0 answers

Conflicts between queryClient.clear() and mock the useParams()

When I add this line to the test setup, the mocking of useParams stops to work. I cannot find why it happens. testsetup.ts import '@testing-library/jest-dom' const queryClient = new QueryClient({ defaultOptions: { queries: { …
podeig
  • 2,597
  • 8
  • 36
  • 60
0
votes
1 answer

Testing Angular Services with MSW causes timeout

EDIT: I should mention, that I only have problems during testing. When I run ng serve and use msw to serve the data everything works correctly. I stumbled upon mswjs recently and wanted to use the mock service workers to test my frontend services…
cffun
  • 1
  • 2
0
votes
0 answers

searchParams - is there automatic conversion from dot notation to bracket notation?

I'm working in a 3rd party code base and trying to understand the search param extraction for the following URL https://example.com/books?filters.author=1c32323cc-fac5-4c5e-a7d3-a5379cdc4417 in the following Mock Service Worker…
chrikrah
  • 181
  • 9
0
votes
0 answers

TypeError: The "options.agent" property must be one of Agent-like Object, undefined, or false. Received an instance of Object

I am trying to write a simple test for logging in. The error message: TypeError: The "options.agent" property must be one of Agent-like Object, undefined, or false. Received an instance of Object The test: import { QueryClient, QueryClientProvider }…
T-O
  • 9
  • 3
0
votes
0 answers

Apollo refetchQueries unit test with vue testing library

I am new to graphql and apollo. I have a useMutation query which on completion perform a refetchQueries operation of 2 other queries. How to write a unit for refetchQueries specific, so that if I remove the refetchQueries code my test should fail. I…
0
votes
1 answer

Mock Service Worker doesn't intercept request

app.js class MyApp { async fetchData() { const response = await fetch('http://myurl.com', { method: 'GET' }); console.log(response); // received: {}, expected: { val: true } } } export { MyApp }; app.test.js import {MyApp}…
elzoy
  • 5,237
  • 11
  • 40
  • 65