Skip to content

Commit e6b5bf6

Browse files
committed
tests: fix tests by mocking vue-demi
1 parent 2c39bde commit e6b5bf6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/useQueryClient.test.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
import * as vue from "vue-demi";
1+
import { inject } from "vue-demi";
22
import { useQueryClient, VUE_REACT_QUERY_CLIENT } from "../src/useQueryClient";
33

4+
jest.mock("vue-demi", () => {
5+
const vue = jest.requireActual("vue-demi");
6+
return {
7+
...vue,
8+
inject: jest.fn(),
9+
};
10+
});
11+
412
describe("useQueryClient", () => {
13+
const injectSpy = inject as jest.Mock;
14+
515
beforeEach(() => {
616
jest.restoreAllMocks();
17+
jest.clearAllMocks();
718
});
819

920
test("should return queryClient when it is provided in the context", () => {
1021
const queryClientMock = { name: "Mocked client" };
11-
const injectSpy = jest
12-
.spyOn(vue, "inject")
13-
.mockReturnValue(queryClientMock);
22+
injectSpy.mockReturnValueOnce(queryClientMock);
1423

1524
const queryClient = useQueryClient();
1625

@@ -20,7 +29,7 @@ describe("useQueryClient", () => {
2029
});
2130

2231
test("should throw an error when queryClient does not exist in the context", () => {
23-
const injectSpy = jest.spyOn(vue, "inject").mockReturnValue(undefined);
32+
injectSpy.mockReturnValueOnce(undefined);
2433

2534
expect(useQueryClient).toThrowError(
2635
Error(

0 commit comments

Comments
 (0)