-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mock adding third random parameter #749
Comments
I can confirm I have the same problem when spying the |
@antoinezanardi I discovered here #567 (comment) that we need to use registerEndpoint to mock the useFetch response, it worked for me, but it is limited, you can't change the responses based on each test, you would need to create a test file to validate an error response and another for success, this suggestion was said here by someone else #551 (comment) |
Sweet technique, I missed that! I actually was also able to change the response, even within a test, in the following way: // usual imports...
const { responseMock } = vi.hoisted(() => {
return {
responseMock: vi.fn().mockImplementation(() => {
console.log("called base!");
return { testDataOfResponse: "baseline" };
}),
};
});
registerEndpoint("/test/", () => responseMock()) The previous code is added at the top of the test file, while then, in the test: // it("test name", () => {
responseMock.mockImplementation(() => {
console.log("called modified!");
return { testDataOfResponse: "test-related response" };
});
// }); You can call the |
Environment
Linux
v20.10.0
3.9.3
3.10.0
2.8.1
npm@10.4.0
-
devtools
,modules
,devServer
,srcDir
,css
,postcss
,i18n
,runtimeConfig
@nuxt/test-utils/module@3.10.0
,@nuxtjs/i18n@8.0.0
-
Reproduction
https://stackblitz.com/edit/spy-use-fetch-is-not-working?file=src%2FuseLogin.nuxt.test.ts
Describe the bug
I'm trying to create a spy for nuxt's composable useFetch and validate what is being passed as a parameter in the call, but for some reason a third random parameter is added
Additional context
No response
Logs
No response
The text was updated successfully, but these errors were encountered: