Skip to content

Commit 38cd749

Browse files
authored
test(vue-query/useIsFetching): add test for outside scope warning in development mode (#10237)
* test(vue-query/useIsFetching): add test for outside scope warning in development mode * refactor(vue-query/useIsFetching): wrap outside scope warning test with 'try/finally' for cleanup safety
1 parent 15d4a1a commit 38cd749

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

packages/vue-query/src/__tests__/useIsFetching.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,20 @@ describe('useIsFetching', () => {
9898

9999
expect(isFetching.value).toStrictEqual(1)
100100
})
101+
102+
test('should warn when used outside of setup function in development mode', () => {
103+
vi.stubEnv('NODE_ENV', 'development')
104+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
105+
106+
try {
107+
useIsFetching()
108+
109+
expect(warnSpy).toHaveBeenCalledWith(
110+
'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.',
111+
)
112+
} finally {
113+
warnSpy.mockRestore()
114+
vi.unstubAllEnvs()
115+
}
116+
})
101117
})

0 commit comments

Comments
 (0)