Skip to content

Commit c13a1e3

Browse files
feat: reactivity aware wrappers for queryClient, queryCache and mutationCache (#144)
* feat: unref wrappers for QueryClient, QueryCache and MutationCache * feat: export wrappers * feat: queryClient wrapper * test: tests for QueryCache and MutationCache * fix: types * test: queryClient
1 parent b06bd0a commit c13a1e3

File tree

9 files changed

+1285
-3
lines changed

9 files changed

+1285
-3
lines changed

src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/* istanbul ignore file */
22

33
export {
4-
QueryClient,
54
QueryObserver,
65
QueriesObserver,
76
InfiniteQueryObserver,
87
MutationObserver,
9-
QueryCache,
10-
MutationCache,
118
hydrate,
129
dehydrate,
1310
focusManager,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { ref } from "vue-demi";
2+
import { MutationCache as MutationCacheOrigin } from "react-query/core";
3+
4+
import { MutationCache } from "../mutationCache";
5+
6+
describe("MutationCache", () => {
7+
beforeAll(() => {
8+
jest.spyOn(MutationCacheOrigin.prototype, "find");
9+
jest.spyOn(MutationCacheOrigin.prototype, "findAll");
10+
});
11+
12+
beforeEach(() => {
13+
jest.clearAllMocks();
14+
});
15+
16+
describe("find", () => {
17+
test("should properly unwrap parameters", async () => {
18+
const mutationCache = new MutationCache();
19+
20+
mutationCache.find({
21+
mutationKey: ref("baz"),
22+
});
23+
24+
expect(MutationCacheOrigin.prototype.find).toBeCalledWith({
25+
exact: true,
26+
mutationKey: "baz",
27+
});
28+
});
29+
});
30+
31+
describe("findAll", () => {
32+
test("should properly unwrap parameters", async () => {
33+
const mutationCache = new MutationCache();
34+
35+
mutationCache.findAll({
36+
mutationKey: ref("baz"),
37+
});
38+
39+
expect(MutationCacheOrigin.prototype.findAll).toBeCalledWith({
40+
mutationKey: "baz",
41+
});
42+
});
43+
});
44+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { ref } from "vue-demi";
2+
import { QueryCache as QueryCacheOrigin } from "react-query/core";
3+
4+
import { QueryCache } from "../queryCache";
5+
6+
describe("QueryCache", () => {
7+
beforeAll(() => {
8+
jest.spyOn(QueryCacheOrigin.prototype, "find");
9+
jest.spyOn(QueryCacheOrigin.prototype, "findAll");
10+
});
11+
12+
beforeEach(() => {
13+
jest.clearAllMocks();
14+
});
15+
16+
describe("find", () => {
17+
test("should properly unwrap parameters", async () => {
18+
const queryCache = new QueryCache();
19+
20+
queryCache.find(["foo", ref("bar")], {
21+
queryKey: ref("baz"),
22+
});
23+
24+
expect(QueryCacheOrigin.prototype.find).toBeCalledWith(["foo", "bar"], {
25+
queryKey: "baz",
26+
});
27+
});
28+
});
29+
30+
describe("findAll", () => {
31+
test("should properly unwrap two parameters", async () => {
32+
const queryCache = new QueryCache();
33+
34+
queryCache.findAll(["foo", ref("bar")], {
35+
queryKey: ref("baz"),
36+
});
37+
38+
expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith(
39+
["foo", "bar"],
40+
{
41+
queryKey: "baz",
42+
}
43+
);
44+
});
45+
46+
test("should properly unwrap one parameter", async () => {
47+
const queryCache = new QueryCache();
48+
49+
queryCache.findAll({
50+
queryKey: ref("baz"),
51+
});
52+
53+
expect(QueryCacheOrigin.prototype.findAll).toBeCalledWith({
54+
queryKey: "baz",
55+
});
56+
});
57+
});
58+
});

0 commit comments

Comments
 (0)