|
| 1 | +// import { successMutator, simpleFetcher } from "./test-utils"; |
| 2 | +import { QueryClient } from "react-query/types/core"; |
| 3 | +import { VueQueryPlugin } from "../vueQueryPlugin"; |
| 4 | +import { VUE_QUERY_CLIENT } from "../useQueryClient"; |
| 5 | + |
| 6 | +const vue3AppMock = { |
| 7 | + provide: jest.fn(), |
| 8 | +}; |
| 9 | + |
| 10 | +describe("VueQueryPlugin", () => { |
| 11 | + beforeEach(() => { |
| 12 | + jest.clearAllMocks(); |
| 13 | + }); |
| 14 | + |
| 15 | + describe("when called without additional options", () => { |
| 16 | + test("should instantiate a client with default clientKey", () => { |
| 17 | + VueQueryPlugin(vue3AppMock); |
| 18 | + |
| 19 | + expect(vue3AppMock.provide).toHaveBeenCalledWith( |
| 20 | + VUE_QUERY_CLIENT, |
| 21 | + expect.objectContaining({ defaultOptions: {} }) |
| 22 | + ); |
| 23 | + }); |
| 24 | + }); |
| 25 | + |
| 26 | + describe("when called with custom clientKey", () => { |
| 27 | + test("should instantiate a client with customized clientKey", () => { |
| 28 | + VueQueryPlugin(vue3AppMock, { queryClientKey: "CUSTOM" }); |
| 29 | + |
| 30 | + expect(vue3AppMock.provide).toHaveBeenCalledWith( |
| 31 | + VUE_QUERY_CLIENT + "CUSTOM", |
| 32 | + expect.objectContaining({ defaultOptions: {} }) |
| 33 | + ); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe("when called with custom client", () => { |
| 38 | + test("should instantiate that custom client", () => { |
| 39 | + const customClient = { mount: jest.fn() } as unknown as QueryClient; |
| 40 | + VueQueryPlugin(vue3AppMock, { queryClient: customClient }); |
| 41 | + |
| 42 | + expect(customClient.mount).toHaveBeenCalled(); |
| 43 | + expect(vue3AppMock.provide).toHaveBeenCalledWith( |
| 44 | + VUE_QUERY_CLIENT, |
| 45 | + customClient |
| 46 | + ); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + describe("when called with custom client condig", () => { |
| 51 | + test("should instantiate a client with the provided config", () => { |
| 52 | + VueQueryPlugin(vue3AppMock, { |
| 53 | + queryClientConfig: { |
| 54 | + defaultOptions: { queries: { enabled: true } }, |
| 55 | + }, |
| 56 | + }); |
| 57 | + |
| 58 | + expect(vue3AppMock.provide).toHaveBeenCalledWith( |
| 59 | + VUE_QUERY_CLIENT, |
| 60 | + expect.objectContaining({ |
| 61 | + defaultOptions: { queries: { enabled: true } }, |
| 62 | + }) |
| 63 | + ); |
| 64 | + }); |
| 65 | + }); |
| 66 | +}); |
0 commit comments