diff --git a/packages/vue-query/src/__tests__/useMutation.test.ts b/packages/vue-query/src/__tests__/useMutation.test.ts index 88991b58dc1..cd135da7147 100644 --- a/packages/vue-query/src/__tests__/useMutation.test.ts +++ b/packages/vue-query/src/__tests__/useMutation.test.ts @@ -386,6 +386,24 @@ describe('useMutation', () => { }) }) + test('should warn when used outside of setup function in development mode', () => { + vi.stubEnv('NODE_ENV', 'development') + const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) + + try { + useMutation({ + mutationFn: (params: string) => sleep(0).then(() => params), + }) + + expect(warnSpy).toHaveBeenCalledWith( + 'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.', + ) + } finally { + warnSpy.mockRestore() + vi.unstubAllEnvs() + } + }) + describe('throwOnError', () => { test('should evaluate throwOnError when mutation is expected to throw', async () => { const err = new Error('Expected mock error. All is well!')