Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions packages/vue-query/src/__tests__/useQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,27 @@ describe('useQuery', () => {
})
})

describe('outside scope warning', () => {
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 {
useQuery({
queryKey: ['outsideScope'],
queryFn: () => sleep(0).then(() => 'data'),
})

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('suspense', () => {
test('should return a Promise', () => {
const getCurrentInstanceSpy = getCurrentInstance as Mock
Expand Down
Loading