Download react-query/packages/vue-query/src/__tests__/useQueryClient.test.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/vue-query/src/__tests__/useQueryClient.test.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/vue-query/src/__tests__/useQueryClient.test.ts
-
curl -L -o useQueryClient.test.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-query/packages/vue-query/src/__tests__/useQueryClient.test.ts
1.75 kB
| import { beforeEach, describe, expect, test, vi } from 'vitest' | |
| import { hasInjectionContext, inject } from 'vue-demi' | |
| import { useQueryClient } from '../useQueryClient' | |
| import { VUE_QUERY_CLIENT } from '../utils' | |
| import type { Mock } from 'vitest' | |
| describe('useQueryClient', () => { | |
| const injectSpy = inject as Mock | |
| const hasInjectionContextSpy = hasInjectionContext as Mock | |
| beforeEach(() => { | |
| vi.restoreAllMocks() | |
| }) | |
| test('should return queryClient when it is provided in the context', () => { | |
| const queryClientMock = { name: 'Mocked client' } | |
| injectSpy.mockReturnValueOnce(queryClientMock) | |
| const queryClient = useQueryClient() | |
| expect(queryClient).toStrictEqual(queryClientMock) | |
| expect(injectSpy).toHaveBeenCalledTimes(1) | |
| expect(injectSpy).toHaveBeenCalledWith(VUE_QUERY_CLIENT) | |
| }) | |
| test('should throw an error when queryClient does not exist in the context', () => { | |
| injectSpy.mockReturnValueOnce(undefined) | |
| expect(useQueryClient).toThrowError() | |
| expect(injectSpy).toHaveBeenCalledTimes(1) | |
| expect(injectSpy).toHaveBeenCalledWith(VUE_QUERY_CLIENT) | |
| }) | |
| test('should throw an error when used outside of setup function', () => { | |
| hasInjectionContextSpy.mockReturnValueOnce(false) | |
| expect(useQueryClient).toThrowError() | |
| expect(hasInjectionContextSpy).toHaveBeenCalledTimes(1) | |
| }) | |
| test('should call inject with a custom key as a suffix', () => { | |
| const queryClientKey = 'foo' | |
| const expectedKeyParameter = `${VUE_QUERY_CLIENT}:${queryClientKey}` | |
| const queryClientMock = { name: 'Mocked client' } | |
| injectSpy.mockReturnValueOnce(queryClientMock) | |
| useQueryClient(queryClientKey) | |
| expect(injectSpy).toHaveBeenCalledWith(expectedKeyParameter) | |
| }) | |
| }) | |