You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letqueryClient: QueryClient;letserver: SetupServer;constroutePath=linkToScenarioDetail("why-is-msw-not-working");consthistory=createMemoryHistory({initialEntries: [routePath],});conststore=configureStore([])();beforeAll(()=>{queryClient=newQueryClient();server=setupServer(
...[rest.get("/msw/reporting_groups/:id",(req,res,ctx)=>{console.log("intercepted",req.url);// (1)returnres(ctx.status(200),ctx.json(reportingGroupMock.mock));}),]);server.listen({onUnhandledRequest: "error",});server.printHandlers();// (3)});afterEach(()=>{server.resetHandlers();queryClient.clear();});afterAll(()=>server.close());describe("EditScenarioPage tests",()=>{test("Should render page",async()=>{// duplicate override just for the sake of debugging MSWserver.use(rest.get("/msw/reporting_groups/:id",(req,res,ctx)=>{console.log("intercepted",req.url);// (2)returnres(ctx.status(200),ctx.json(reportingGroupMock.mock));}));render(<Providerstore={store}><QueryClientProviderclient={queryClient}><Routerhistory={history}><Routepath={`/app/scenarios/:scenarioId`}><EditScenarioPage/></Route></Router></QueryClientProvider></Provider>);awaitwaitFor(()=>{expect(screen.getByLabelText("Name").value).toBe("Why Is MSW Not Working");});});});
console log on 5 does not print (as expected given fetch has been intercepted by MSW?)
No matter what I've done with the MSW handler configuration, the request does not get intercepted. I've also inspected the virtual DOM with testing library's screen.debug() - none of the mock data is coming through.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a Jest test here:
with relevant component code:
No matter what I've done with the MSW handler configuration, the request does not get intercepted. I've also inspected the virtual DOM with testing library's
screen.debug()
- none of the mock data is coming through.Running:
on Node v18.15.0
Beta Was this translation helpful? Give feedback.
All reactions