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
is there a known issue with msw 2.0 in nextjs? do an initial data fetch with react 19 server component and i mock this using the normal server msw way using server from msw/node. I also use api routes from nextjs to mock the api call for server component. I think this part might be the issue as I always render the component in the test, even though i try to simulate an error with a test = server.use(
http.get("/api/someapipath", () => {
console.log("API request intercepted"); // Debugging
return HttpResponse.error();
})
);
I think the nextjs api route is the problem. I'm not sure...( I have set up server in msw correctly, I've followed the docs step by step and I've set it up successfully before in projects not using nextjs with server components so I'm pretty sure the issue is not there)... Is there a way to override it in the tests?
Additional information
describe("- API Error Handling",()=>{it("renders error message when API fails",async()=>{server.use(http.get("/api/someapipath",()=>{console.log("API request intercepted");// DebuggingreturnHttpResponse.error();}));render(awaitDashboardTestWrapper());// Only render after setting up the mockawaitwaitFor(()=>{expect(screen.getByText(/Failedtoloaddashboarddata/i)).toBeInTheDocument();});});});andinmyapirouteihaveif(process.env.NODE_ENV==="development"&&process.env.NEXT_PUBLIC_API_MOCKING==="enabled"){returnnewResponse(JSON.stringify(Mock),{status: 200,headers: {"Content-Type": "application/json",},});}else{// call real api
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
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
is there a known issue with msw 2.0 in nextjs? do an initial data fetch with react 19 server component and i mock this using the normal server msw way using server from msw/node. I also use api routes from nextjs to mock the api call for server component. I think this part might be the issue as I always render the component in the test, even though i try to simulate an error with a test = server.use(
http.get("/api/someapipath", () => {
console.log("API request intercepted"); // Debugging
return HttpResponse.error();
})
);
I think the nextjs api route is the problem. I'm not sure...( I have set up server in msw correctly, I've followed the docs step by step and I've set it up successfully before in projects not using nextjs with server components so I'm pretty sure the issue is not there)... Is there a way to override it in the tests?
Additional information
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions