@dhis2/app-service-data 3.11.3 → 3.12.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/__tests__/integration.test.js +6 -15
- package/build/cjs/__tests__/mutations.test.js +4 -11
- package/build/cjs/engine/DataEngine.js +4 -14
- package/build/cjs/engine/DataEngine.test.js +0 -2
- package/build/cjs/engine/helpers/getMutationFetchType.js +0 -2
- package/build/cjs/engine/helpers/getMutationFetchType.test.js +0 -1
- package/build/cjs/engine/helpers/resolveDynamicQuery.js +0 -2
- package/build/cjs/engine/helpers/resolveDynamicQuery.test.js +3 -4
- package/build/cjs/engine/helpers/validate.js +0 -21
- package/build/cjs/engine/helpers/validate.test.js +0 -1
- package/build/cjs/engine/index.js +0 -18
- package/build/cjs/engine/types/FetchError.js +3 -8
- package/build/cjs/engine/types/FetchError.test.js +0 -1
- package/build/cjs/engine/types/InvalidQueryError.js +3 -8
- package/build/cjs/index.js +0 -2
- package/build/cjs/links/CustomDataLink.js +3 -17
- package/build/cjs/links/CustomDataLink.test.js +0 -1
- package/build/cjs/links/ErrorLink.js +3 -7
- package/build/cjs/links/RestAPILink/fetchData.js +12 -22
- package/build/cjs/links/RestAPILink/fetchData.test.js +0 -2
- package/build/cjs/links/RestAPILink/metadataResources.js +9 -7
- package/build/cjs/links/RestAPILink/path.js +0 -3
- package/build/cjs/links/RestAPILink/path.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -14
- package/build/cjs/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.js +4 -31
- package/build/cjs/links/RestAPILink/queryToRequestOptions/requestContentType.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -39
- package/build/cjs/links/RestAPILink/queryToRequestOptions/textPlainMatchers.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.js +0 -2
- package/build/cjs/links/RestAPILink/queryToRequestOptions/xWwwFormUrlencodedMatchers.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToRequestOptions.js +0 -9
- package/build/cjs/links/RestAPILink/queryToRequestOptions.test.js +0 -1
- package/build/cjs/links/RestAPILink/queryToResourcePath.js +3 -24
- package/build/cjs/links/RestAPILink/queryToResourcePath.test.js +2 -4
- package/build/cjs/links/RestAPILink/validateQuery.js +4 -18
- package/build/cjs/links/RestAPILink/validateQuery.test.js +0 -1
- package/build/cjs/links/RestAPILink.js +3 -14
- package/build/cjs/links/RestAPILink.test.js +0 -2
- package/build/cjs/links/index.js +0 -6
- package/build/cjs/react/components/CustomDataProvider.js +3 -12
- package/build/cjs/react/components/DataMutation.js +1 -4
- package/build/cjs/react/components/DataProvider.js +11 -16
- package/build/cjs/react/components/DataProvider.test.js +2 -9
- package/build/cjs/react/components/DataQuery.js +1 -4
- package/build/cjs/react/context/DataContext.js +2 -8
- package/build/cjs/react/context/defaultContext.js +2 -6
- package/build/cjs/react/context/defaultContext.test.js +0 -1
- package/build/cjs/react/hooks/mergeAndCompareVariables.js +4 -6
- package/build/cjs/react/hooks/mergeAndCompareVariables.test.js +2 -3
- package/build/cjs/react/hooks/stableVariablesHash.js +11 -16
- package/build/cjs/react/hooks/stableVariablesHash.test.js +0 -1
- package/build/cjs/react/hooks/useDataEngine.js +0 -4
- package/build/cjs/react/hooks/useDataMutation.js +0 -7
- package/build/cjs/react/hooks/useDataMutation.test.js +42 -71
- package/build/cjs/react/hooks/useDataQuery.js +26 -44
- package/build/cjs/react/hooks/useDataQuery.test.js +318 -374
- package/build/cjs/react/hooks/useQueryExecutor.js +6 -14
- package/build/cjs/react/hooks/useQueryExecutor.test.js +42 -45
- package/build/cjs/react/hooks/useStaticInput.js +0 -3
- package/build/cjs/react/hooks/useStaticInput.test.js +8 -10
- package/build/cjs/react/index.js +0 -11
- package/build/cjs/setupRTL.js +1 -2
- package/build/es/__tests__/integration.test.js +4 -8
- package/build/es/__tests__/mutations.test.js +2 -4
- package/build/es/engine/DataEngine.js +3 -8
- package/build/es/engine/DataEngine.test.js +0 -1
- package/build/es/engine/helpers/resolveDynamicQuery.test.js +3 -3
- package/build/es/engine/helpers/validate.js +0 -13
- package/build/es/engine/types/FetchError.js +3 -6
- package/build/es/engine/types/InvalidQueryError.js +3 -6
- package/build/es/links/CustomDataLink.js +3 -15
- package/build/es/links/ErrorLink.js +3 -5
- package/build/es/links/RestAPILink/fetchData.js +12 -16
- package/build/es/links/RestAPILink/metadataResources.js +8 -3
- package/build/es/links/RestAPILink/path.js +0 -1
- package/build/es/links/RestAPILink/queryToRequestOptions/multipartFormDataMatchers.js +9 -4
- package/build/es/links/RestAPILink/queryToRequestOptions/requestContentType.js +2 -19
- package/build/es/links/RestAPILink/queryToRequestOptions/textPlainMatchers.js +22 -19
- package/build/es/links/RestAPILink/queryToRequestOptions.js +0 -7
- package/build/es/links/RestAPILink/queryToResourcePath.js +3 -21
- package/build/es/links/RestAPILink/queryToResourcePath.test.js +2 -3
- package/build/es/links/RestAPILink/validateQuery.js +4 -16
- package/build/es/links/RestAPILink.js +3 -8
- package/build/es/react/components/CustomDataProvider.js +2 -2
- package/build/es/react/components/DataMutation.js +1 -1
- package/build/es/react/components/DataProvider.js +9 -3
- package/build/es/react/components/DataProvider.test.js +1 -1
- package/build/es/react/components/DataQuery.js +1 -1
- package/build/es/react/hooks/mergeAndCompareVariables.js +4 -3
- package/build/es/react/hooks/mergeAndCompareVariables.test.js +2 -1
- package/build/es/react/hooks/stableVariablesHash.js +11 -14
- package/build/es/react/hooks/useDataMutation.test.js +17 -39
- package/build/es/react/hooks/useDataQuery.js +26 -37
- package/build/es/react/hooks/useDataQuery.test.js +268 -318
- package/build/es/react/hooks/useQueryExecutor.js +6 -9
- package/build/es/react/hooks/useQueryExecutor.test.js +33 -34
- package/build/es/react/hooks/useStaticInput.test.js +6 -6
- package/build/es/setupRTL.js +1 -1
- package/build/types/engine/types/ExecuteOptions.d.ts +1 -1
- package/build/types/engine/types/FetchError.d.ts +2 -2
- package/build/types/engine/types/JsonValue.d.ts +1 -1
- package/build/types/engine/types/Mutation.d.ts +2 -2
- package/build/types/engine/types/PossiblyDynamic.d.ts +1 -1
- package/build/types/engine/types/Query.d.ts +3 -3
- package/build/types/engine/types/QueryParameters.d.ts +4 -4
- package/build/types/links/CustomDataLink.d.ts +2 -2
- package/build/types/links/RestAPILink/queryToRequestOptions/requestContentType.d.ts +1 -1
- package/build/types/links/RestAPILink/queryToRequestOptions.d.ts +1 -1
- package/build/types/react/components/DataProvider.d.ts +2 -11
- package/build/types/react/hooks/mergeAndCompareVariables.d.ts +1 -1
- package/build/types/types.d.ts +6 -6
- package/package.json +5 -5
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
3
|
+
var _react = require("@testing-library/react");
|
|
5
4
|
var React = _interopRequireWildcard(require("react"));
|
|
6
|
-
|
|
7
5
|
var _CustomDataProvider = require("../components/CustomDataProvider");
|
|
8
|
-
|
|
9
6
|
var _useDataQuery = require("./useDataQuery");
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
|
|
7
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
8
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
9
|
describe('useDataQuery', () => {
|
|
16
10
|
describe('parameters: onComplete', () => {
|
|
17
11
|
it('Should call onComplete with the data after a successful fetch', async () => {
|
|
@@ -23,8 +17,7 @@ describe('useDataQuery', () => {
|
|
|
23
17
|
const data = {
|
|
24
18
|
answer: 42
|
|
25
19
|
};
|
|
26
|
-
|
|
27
|
-
const wrapper = (_ref) => {
|
|
20
|
+
const wrapper = _ref => {
|
|
28
21
|
let {
|
|
29
22
|
children
|
|
30
23
|
} = _ref;
|
|
@@ -32,13 +25,11 @@ describe('useDataQuery', () => {
|
|
|
32
25
|
data: data
|
|
33
26
|
}, children);
|
|
34
27
|
};
|
|
35
|
-
|
|
36
28
|
const onComplete = jest.fn();
|
|
37
29
|
const onError = jest.fn();
|
|
38
30
|
const {
|
|
39
|
-
result
|
|
40
|
-
|
|
41
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
31
|
+
result
|
|
32
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
42
33
|
lazy: false,
|
|
43
34
|
onComplete,
|
|
44
35
|
onError
|
|
@@ -49,15 +40,16 @@ describe('useDataQuery', () => {
|
|
|
49
40
|
loading: true,
|
|
50
41
|
called: true
|
|
51
42
|
});
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
x: 42
|
|
55
|
-
});
|
|
56
|
-
expect(onError).not.toHaveBeenCalled();
|
|
57
|
-
expect(result.current).toMatchObject({
|
|
58
|
-
data: {
|
|
43
|
+
await (0, _react.waitFor)(() => {
|
|
44
|
+
expect(onComplete).toHaveBeenCalledWith({
|
|
59
45
|
x: 42
|
|
60
|
-
}
|
|
46
|
+
});
|
|
47
|
+
expect(onError).not.toHaveBeenCalled();
|
|
48
|
+
expect(result.current).toMatchObject({
|
|
49
|
+
data: {
|
|
50
|
+
x: 42
|
|
51
|
+
}
|
|
52
|
+
});
|
|
61
53
|
});
|
|
62
54
|
});
|
|
63
55
|
});
|
|
@@ -74,8 +66,7 @@ describe('useDataQuery', () => {
|
|
|
74
66
|
throw expectedError;
|
|
75
67
|
}
|
|
76
68
|
};
|
|
77
|
-
|
|
78
|
-
const wrapper = (_ref2) => {
|
|
69
|
+
const wrapper = _ref2 => {
|
|
79
70
|
let {
|
|
80
71
|
children
|
|
81
72
|
} = _ref2;
|
|
@@ -83,13 +74,11 @@ describe('useDataQuery', () => {
|
|
|
83
74
|
data: data
|
|
84
75
|
}, children);
|
|
85
76
|
};
|
|
86
|
-
|
|
87
77
|
const onComplete = jest.fn();
|
|
88
78
|
const onError = jest.fn();
|
|
89
79
|
const {
|
|
90
|
-
result
|
|
91
|
-
|
|
92
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
80
|
+
result
|
|
81
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
93
82
|
onError,
|
|
94
83
|
onComplete
|
|
95
84
|
}), {
|
|
@@ -99,11 +88,12 @@ describe('useDataQuery', () => {
|
|
|
99
88
|
loading: true,
|
|
100
89
|
called: true
|
|
101
90
|
});
|
|
102
|
-
await
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
await (0, _react.waitFor)(() => {
|
|
92
|
+
expect(onError).toHaveBeenCalledWith(expectedError);
|
|
93
|
+
expect(onComplete).not.toHaveBeenCalled();
|
|
94
|
+
expect(result.current).toMatchObject({
|
|
95
|
+
error: expectedError
|
|
96
|
+
});
|
|
107
97
|
});
|
|
108
98
|
});
|
|
109
99
|
});
|
|
@@ -116,7 +106,7 @@ describe('useDataQuery', () => {
|
|
|
116
106
|
const query = {
|
|
117
107
|
x: {
|
|
118
108
|
resource: 'answer',
|
|
119
|
-
id:
|
|
109
|
+
id: _ref3 => {
|
|
120
110
|
let {
|
|
121
111
|
id
|
|
122
112
|
} = _ref3;
|
|
@@ -128,11 +118,9 @@ describe('useDataQuery', () => {
|
|
|
128
118
|
let {
|
|
129
119
|
id
|
|
130
120
|
} = _ref4;
|
|
131
|
-
|
|
132
121
|
switch (id) {
|
|
133
122
|
case one:
|
|
134
123
|
return Promise.resolve(resultOne);
|
|
135
|
-
|
|
136
124
|
case two:
|
|
137
125
|
return Promise.resolve(resultTwo);
|
|
138
126
|
}
|
|
@@ -140,8 +128,7 @@ describe('useDataQuery', () => {
|
|
|
140
128
|
const data = {
|
|
141
129
|
answer: mockSpy
|
|
142
130
|
};
|
|
143
|
-
|
|
144
|
-
const wrapper = (_ref5) => {
|
|
131
|
+
const wrapper = _ref5 => {
|
|
145
132
|
let {
|
|
146
133
|
children
|
|
147
134
|
} = _ref5;
|
|
@@ -149,7 +136,6 @@ describe('useDataQuery', () => {
|
|
|
149
136
|
data: data
|
|
150
137
|
}, children);
|
|
151
138
|
};
|
|
152
|
-
|
|
153
139
|
const initialProps = {
|
|
154
140
|
query,
|
|
155
141
|
options: {
|
|
@@ -160,9 +146,8 @@ describe('useDataQuery', () => {
|
|
|
160
146
|
};
|
|
161
147
|
const {
|
|
162
148
|
result,
|
|
163
|
-
waitForNextUpdate,
|
|
164
149
|
rerender
|
|
165
|
-
} = (0,
|
|
150
|
+
} = (0, _react.renderHook)(props => (0, _useDataQuery.useDataQuery)(props.query, props.options), {
|
|
166
151
|
wrapper,
|
|
167
152
|
initialProps
|
|
168
153
|
});
|
|
@@ -171,13 +156,14 @@ describe('useDataQuery', () => {
|
|
|
171
156
|
loading: true,
|
|
172
157
|
called: true
|
|
173
158
|
});
|
|
174
|
-
await
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
159
|
+
await (0, _react.waitFor)(() => {
|
|
160
|
+
expect(result.current).toMatchObject({
|
|
161
|
+
data: {
|
|
162
|
+
x: resultOne
|
|
163
|
+
}
|
|
164
|
+
});
|
|
179
165
|
});
|
|
180
|
-
(0,
|
|
166
|
+
(0, _react.act)(() => {
|
|
181
167
|
const newProps = {
|
|
182
168
|
query,
|
|
183
169
|
options: {
|
|
@@ -207,8 +193,7 @@ describe('useDataQuery', () => {
|
|
|
207
193
|
const data = {
|
|
208
194
|
answer: mockSpy
|
|
209
195
|
};
|
|
210
|
-
|
|
211
|
-
const wrapper = (_ref6) => {
|
|
196
|
+
const wrapper = _ref6 => {
|
|
212
197
|
let {
|
|
213
198
|
children
|
|
214
199
|
} = _ref6;
|
|
@@ -216,25 +201,24 @@ describe('useDataQuery', () => {
|
|
|
216
201
|
data: data
|
|
217
202
|
}, children);
|
|
218
203
|
};
|
|
219
|
-
|
|
220
204
|
const {
|
|
221
|
-
result
|
|
222
|
-
|
|
223
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
205
|
+
result
|
|
206
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
224
207
|
wrapper
|
|
225
208
|
});
|
|
226
209
|
expect(result.current).toMatchObject({
|
|
227
210
|
loading: true,
|
|
228
211
|
called: true
|
|
229
212
|
});
|
|
230
|
-
await
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
213
|
+
await (0, _react.waitFor)(() => {
|
|
214
|
+
expect(mockSpy).toHaveBeenCalledTimes(1);
|
|
215
|
+
expect(result.current).toMatchObject({
|
|
216
|
+
loading: false,
|
|
217
|
+
called: true,
|
|
218
|
+
data: {
|
|
219
|
+
x: 42
|
|
220
|
+
}
|
|
221
|
+
});
|
|
238
222
|
});
|
|
239
223
|
});
|
|
240
224
|
});
|
|
@@ -258,8 +242,7 @@ describe('useDataQuery', () => {
|
|
|
258
242
|
resource: 'answer'
|
|
259
243
|
}
|
|
260
244
|
};
|
|
261
|
-
|
|
262
|
-
const wrapper = (_ref7) => {
|
|
245
|
+
const wrapper = _ref7 => {
|
|
263
246
|
let {
|
|
264
247
|
children
|
|
265
248
|
} = _ref7;
|
|
@@ -268,11 +251,9 @@ describe('useDataQuery', () => {
|
|
|
268
251
|
queryClientOptions: queryClientOptions
|
|
269
252
|
}, children);
|
|
270
253
|
};
|
|
271
|
-
|
|
272
254
|
const {
|
|
273
|
-
result
|
|
274
|
-
|
|
275
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
255
|
+
result
|
|
256
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
276
257
|
wrapper
|
|
277
258
|
});
|
|
278
259
|
expect(mockSpy).toHaveBeenCalledTimes(1);
|
|
@@ -280,16 +261,17 @@ describe('useDataQuery', () => {
|
|
|
280
261
|
loading: true,
|
|
281
262
|
called: true
|
|
282
263
|
});
|
|
283
|
-
await
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
264
|
+
await (0, _react.waitFor)(() => {
|
|
265
|
+
// Now the cache will contain a value for 'answer' without variables
|
|
266
|
+
expect(result.current).toMatchObject({
|
|
267
|
+
loading: false,
|
|
268
|
+
called: true,
|
|
269
|
+
data: {
|
|
270
|
+
x: 42
|
|
271
|
+
}
|
|
272
|
+
});
|
|
291
273
|
});
|
|
292
|
-
(0,
|
|
274
|
+
(0, _react.act)(() => {
|
|
293
275
|
// Add a variable to the request to ensure a different cache key
|
|
294
276
|
result.current.refetch({
|
|
295
277
|
one: 1
|
|
@@ -299,21 +281,23 @@ describe('useDataQuery', () => {
|
|
|
299
281
|
expect(result.current).toMatchObject({
|
|
300
282
|
loading: true
|
|
301
283
|
});
|
|
302
|
-
await
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
284
|
+
await (0, _react.waitFor)(() => {
|
|
285
|
+
// Now the cache will contain a value for 'answer' with and without variables
|
|
286
|
+
expect(result.current).toMatchObject({
|
|
287
|
+
loading: false,
|
|
288
|
+
data: {
|
|
289
|
+
x: 43
|
|
290
|
+
}
|
|
291
|
+
});
|
|
309
292
|
});
|
|
310
|
-
(0,
|
|
293
|
+
(0, _react.act)(() => {
|
|
311
294
|
// Request the resource without variables again
|
|
312
295
|
result.current.refetch({
|
|
313
296
|
one: undefined
|
|
314
297
|
});
|
|
315
|
-
});
|
|
298
|
+
});
|
|
316
299
|
|
|
300
|
+
// This should return the resource from the cache without fetching
|
|
317
301
|
expect(mockSpy).toHaveBeenCalledTimes(2);
|
|
318
302
|
expect(result.current).toMatchObject({
|
|
319
303
|
loading: false,
|
|
@@ -335,8 +319,7 @@ describe('useDataQuery', () => {
|
|
|
335
319
|
resource: 'answer'
|
|
336
320
|
}
|
|
337
321
|
};
|
|
338
|
-
|
|
339
|
-
const wrapper = (_ref8) => {
|
|
322
|
+
const wrapper = _ref8 => {
|
|
340
323
|
let {
|
|
341
324
|
children
|
|
342
325
|
} = _ref8;
|
|
@@ -344,11 +327,9 @@ describe('useDataQuery', () => {
|
|
|
344
327
|
data: data
|
|
345
328
|
}, children);
|
|
346
329
|
};
|
|
347
|
-
|
|
348
330
|
const {
|
|
349
|
-
result
|
|
350
|
-
|
|
351
|
-
} = (0, _reactHooks.renderHook)(() => {
|
|
331
|
+
result
|
|
332
|
+
} = (0, _react.renderHook)(() => {
|
|
352
333
|
const one = (0, _useDataQuery.useDataQuery)(query);
|
|
353
334
|
const two = (0, _useDataQuery.useDataQuery)(query);
|
|
354
335
|
const three = (0, _useDataQuery.useDataQuery)(query);
|
|
@@ -362,16 +343,17 @@ describe('useDataQuery', () => {
|
|
|
362
343
|
};
|
|
363
344
|
expect(mockSpy).toHaveBeenCalledTimes(1);
|
|
364
345
|
expect(result.current).toMatchObject([loading, loading, loading]);
|
|
365
|
-
await
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
346
|
+
await (0, _react.waitFor)(() => {
|
|
347
|
+
const done = {
|
|
348
|
+
loading: false,
|
|
349
|
+
called: true,
|
|
350
|
+
data: {
|
|
351
|
+
x: 42
|
|
352
|
+
}
|
|
353
|
+
};
|
|
354
|
+
expect(mockSpy).toHaveBeenCalledTimes(1);
|
|
355
|
+
expect(result.current).toMatchObject([done, done, done]);
|
|
356
|
+
});
|
|
375
357
|
});
|
|
376
358
|
});
|
|
377
359
|
describe('return values: data', () => {
|
|
@@ -384,8 +366,7 @@ describe('useDataQuery', () => {
|
|
|
384
366
|
const data = {
|
|
385
367
|
answer: 42
|
|
386
368
|
};
|
|
387
|
-
|
|
388
|
-
const wrapper = (_ref9) => {
|
|
369
|
+
const wrapper = _ref9 => {
|
|
389
370
|
let {
|
|
390
371
|
children
|
|
391
372
|
} = _ref9;
|
|
@@ -393,24 +374,23 @@ describe('useDataQuery', () => {
|
|
|
393
374
|
data: data
|
|
394
375
|
}, children);
|
|
395
376
|
};
|
|
396
|
-
|
|
397
377
|
const {
|
|
398
|
-
result
|
|
399
|
-
|
|
400
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
378
|
+
result
|
|
379
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
401
380
|
wrapper
|
|
402
381
|
});
|
|
403
382
|
expect(result.current).toMatchObject({
|
|
404
383
|
loading: true,
|
|
405
384
|
called: true
|
|
406
385
|
});
|
|
407
|
-
await
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
386
|
+
await (0, _react.waitFor)(() => {
|
|
387
|
+
expect(result.current).toMatchObject({
|
|
388
|
+
loading: false,
|
|
389
|
+
called: true,
|
|
390
|
+
data: {
|
|
391
|
+
x: 42
|
|
392
|
+
}
|
|
393
|
+
});
|
|
414
394
|
});
|
|
415
395
|
});
|
|
416
396
|
it('Should return the data for a multiple resource query on success', async () => {
|
|
@@ -426,8 +406,7 @@ describe('useDataQuery', () => {
|
|
|
426
406
|
answer: 42,
|
|
427
407
|
opposite: 24
|
|
428
408
|
};
|
|
429
|
-
|
|
430
|
-
const wrapper = (_ref10) => {
|
|
409
|
+
const wrapper = _ref10 => {
|
|
431
410
|
let {
|
|
432
411
|
children
|
|
433
412
|
} = _ref10;
|
|
@@ -435,25 +414,24 @@ describe('useDataQuery', () => {
|
|
|
435
414
|
data: data
|
|
436
415
|
}, children);
|
|
437
416
|
};
|
|
438
|
-
|
|
439
417
|
const {
|
|
440
|
-
result
|
|
441
|
-
|
|
442
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
418
|
+
result
|
|
419
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
443
420
|
wrapper
|
|
444
421
|
});
|
|
445
422
|
expect(result.current).toMatchObject({
|
|
446
423
|
loading: true,
|
|
447
424
|
called: true
|
|
448
425
|
});
|
|
449
|
-
await
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
426
|
+
await (0, _react.waitFor)(() => {
|
|
427
|
+
expect(result.current).toMatchObject({
|
|
428
|
+
loading: false,
|
|
429
|
+
called: true,
|
|
430
|
+
data: {
|
|
431
|
+
x: 42,
|
|
432
|
+
y: 24
|
|
433
|
+
}
|
|
434
|
+
});
|
|
457
435
|
});
|
|
458
436
|
});
|
|
459
437
|
});
|
|
@@ -470,8 +448,7 @@ describe('useDataQuery', () => {
|
|
|
470
448
|
throw expectedError;
|
|
471
449
|
}
|
|
472
450
|
};
|
|
473
|
-
|
|
474
|
-
const wrapper = (_ref11) => {
|
|
451
|
+
const wrapper = _ref11 => {
|
|
475
452
|
let {
|
|
476
453
|
children
|
|
477
454
|
} = _ref11;
|
|
@@ -479,22 +456,21 @@ describe('useDataQuery', () => {
|
|
|
479
456
|
data: data
|
|
480
457
|
}, children);
|
|
481
458
|
};
|
|
482
|
-
|
|
483
459
|
const {
|
|
484
|
-
result
|
|
485
|
-
|
|
486
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
460
|
+
result
|
|
461
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
487
462
|
wrapper
|
|
488
463
|
});
|
|
489
464
|
expect(result.current).toMatchObject({
|
|
490
465
|
loading: true,
|
|
491
466
|
called: true
|
|
492
467
|
});
|
|
493
|
-
await
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
468
|
+
await (0, _react.waitFor)(() => {
|
|
469
|
+
expect(result.current).toMatchObject({
|
|
470
|
+
loading: false,
|
|
471
|
+
called: true,
|
|
472
|
+
error: expectedError
|
|
473
|
+
});
|
|
498
474
|
});
|
|
499
475
|
});
|
|
500
476
|
it('Should return errors it encounters for multiple resource queries', async () => {
|
|
@@ -513,8 +489,7 @@ describe('useDataQuery', () => {
|
|
|
513
489
|
},
|
|
514
490
|
opposite: 24
|
|
515
491
|
};
|
|
516
|
-
|
|
517
|
-
const wrapper = (_ref12) => {
|
|
492
|
+
const wrapper = _ref12 => {
|
|
518
493
|
let {
|
|
519
494
|
children
|
|
520
495
|
} = _ref12;
|
|
@@ -522,22 +497,21 @@ describe('useDataQuery', () => {
|
|
|
522
497
|
data: data
|
|
523
498
|
}, children);
|
|
524
499
|
};
|
|
525
|
-
|
|
526
500
|
const {
|
|
527
|
-
result
|
|
528
|
-
|
|
529
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
501
|
+
result
|
|
502
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
530
503
|
wrapper
|
|
531
504
|
});
|
|
532
505
|
expect(result.current).toMatchObject({
|
|
533
506
|
loading: true,
|
|
534
507
|
called: true
|
|
535
508
|
});
|
|
536
|
-
await
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
509
|
+
await (0, _react.waitFor)(() => {
|
|
510
|
+
expect(result.current).toMatchObject({
|
|
511
|
+
loading: false,
|
|
512
|
+
called: true,
|
|
513
|
+
error: expectedError
|
|
514
|
+
});
|
|
541
515
|
});
|
|
542
516
|
});
|
|
543
517
|
});
|
|
@@ -556,8 +530,7 @@ describe('useDataQuery', () => {
|
|
|
556
530
|
resource: 'answer'
|
|
557
531
|
}
|
|
558
532
|
};
|
|
559
|
-
|
|
560
|
-
const wrapper = (_ref13) => {
|
|
533
|
+
const wrapper = _ref13 => {
|
|
561
534
|
let {
|
|
562
535
|
children
|
|
563
536
|
} = _ref13;
|
|
@@ -565,21 +538,19 @@ describe('useDataQuery', () => {
|
|
|
565
538
|
data: data
|
|
566
539
|
}, children);
|
|
567
540
|
};
|
|
568
|
-
|
|
569
541
|
const {
|
|
570
|
-
result
|
|
571
|
-
|
|
572
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
542
|
+
result
|
|
543
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
573
544
|
lazy: true
|
|
574
545
|
}), {
|
|
575
546
|
wrapper
|
|
576
547
|
});
|
|
577
548
|
expect(spy).not.toHaveBeenCalled();
|
|
578
549
|
const initialRefetch = result.current.refetch;
|
|
579
|
-
(0,
|
|
550
|
+
(0, _react.act)(() => {
|
|
580
551
|
initialRefetch();
|
|
581
552
|
});
|
|
582
|
-
await waitFor(() => {
|
|
553
|
+
await (0, _react.waitFor)(() => {
|
|
583
554
|
expect(result.current).toMatchObject({
|
|
584
555
|
loading: false,
|
|
585
556
|
called: true,
|
|
@@ -589,10 +560,10 @@ describe('useDataQuery', () => {
|
|
|
589
560
|
});
|
|
590
561
|
});
|
|
591
562
|
expect(spy).toHaveBeenCalledTimes(1);
|
|
592
|
-
(0,
|
|
563
|
+
(0, _react.act)(() => {
|
|
593
564
|
initialRefetch();
|
|
594
565
|
});
|
|
595
|
-
await waitFor(() => {
|
|
566
|
+
await (0, _react.waitFor)(() => {
|
|
596
567
|
expect(result.current).toMatchObject({
|
|
597
568
|
loading: false,
|
|
598
569
|
called: true,
|
|
@@ -609,7 +580,6 @@ describe('useDataQuery', () => {
|
|
|
609
580
|
if (query.id === '1') {
|
|
610
581
|
return 42;
|
|
611
582
|
}
|
|
612
|
-
|
|
613
583
|
return 0;
|
|
614
584
|
});
|
|
615
585
|
const data = {
|
|
@@ -618,7 +588,7 @@ describe('useDataQuery', () => {
|
|
|
618
588
|
const query = {
|
|
619
589
|
x: {
|
|
620
590
|
resource: 'answer',
|
|
621
|
-
id:
|
|
591
|
+
id: _ref14 => {
|
|
622
592
|
let {
|
|
623
593
|
id
|
|
624
594
|
} = _ref14;
|
|
@@ -626,8 +596,7 @@ describe('useDataQuery', () => {
|
|
|
626
596
|
}
|
|
627
597
|
}
|
|
628
598
|
};
|
|
629
|
-
|
|
630
|
-
const wrapper = (_ref15) => {
|
|
599
|
+
const wrapper = _ref15 => {
|
|
631
600
|
let {
|
|
632
601
|
children
|
|
633
602
|
} = _ref15;
|
|
@@ -635,22 +604,20 @@ describe('useDataQuery', () => {
|
|
|
635
604
|
data: data
|
|
636
605
|
}, children);
|
|
637
606
|
};
|
|
638
|
-
|
|
639
607
|
const {
|
|
640
|
-
result
|
|
641
|
-
|
|
642
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
608
|
+
result
|
|
609
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
643
610
|
lazy: true
|
|
644
611
|
}), {
|
|
645
612
|
wrapper
|
|
646
613
|
});
|
|
647
614
|
expect(spy).not.toHaveBeenCalled();
|
|
648
|
-
(0,
|
|
615
|
+
(0, _react.act)(() => {
|
|
649
616
|
result.current.refetch({
|
|
650
617
|
id: '1'
|
|
651
618
|
});
|
|
652
619
|
});
|
|
653
|
-
await waitFor(() => {
|
|
620
|
+
await (0, _react.waitFor)(() => {
|
|
654
621
|
expect(result.current).toMatchObject({
|
|
655
622
|
loading: false,
|
|
656
623
|
called: true,
|
|
@@ -666,7 +633,6 @@ describe('useDataQuery', () => {
|
|
|
666
633
|
if (query.id === '1') {
|
|
667
634
|
return 42;
|
|
668
635
|
}
|
|
669
|
-
|
|
670
636
|
return 0;
|
|
671
637
|
});
|
|
672
638
|
const data = {
|
|
@@ -675,7 +641,7 @@ describe('useDataQuery', () => {
|
|
|
675
641
|
const query = {
|
|
676
642
|
x: {
|
|
677
643
|
resource: 'answer',
|
|
678
|
-
id:
|
|
644
|
+
id: _ref16 => {
|
|
679
645
|
let {
|
|
680
646
|
id
|
|
681
647
|
} = _ref16;
|
|
@@ -683,8 +649,7 @@ describe('useDataQuery', () => {
|
|
|
683
649
|
}
|
|
684
650
|
}
|
|
685
651
|
};
|
|
686
|
-
|
|
687
|
-
const wrapper = (_ref17) => {
|
|
652
|
+
const wrapper = _ref17 => {
|
|
688
653
|
let {
|
|
689
654
|
children
|
|
690
655
|
} = _ref17;
|
|
@@ -692,11 +657,9 @@ describe('useDataQuery', () => {
|
|
|
692
657
|
data: data
|
|
693
658
|
}, children);
|
|
694
659
|
};
|
|
695
|
-
|
|
696
660
|
const {
|
|
697
|
-
result
|
|
698
|
-
|
|
699
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
661
|
+
result
|
|
662
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
700
663
|
lazy: true,
|
|
701
664
|
variables: {
|
|
702
665
|
id: '1'
|
|
@@ -705,12 +668,12 @@ describe('useDataQuery', () => {
|
|
|
705
668
|
wrapper
|
|
706
669
|
});
|
|
707
670
|
expect(spy).not.toHaveBeenCalled();
|
|
708
|
-
(0,
|
|
671
|
+
(0, _react.act)(() => {
|
|
709
672
|
result.current.refetch({
|
|
710
673
|
id: '1'
|
|
711
674
|
});
|
|
712
675
|
});
|
|
713
|
-
await waitFor(() => {
|
|
676
|
+
await (0, _react.waitFor)(() => {
|
|
714
677
|
expect(result.current).toMatchObject({
|
|
715
678
|
loading: false,
|
|
716
679
|
called: true,
|
|
@@ -730,8 +693,7 @@ describe('useDataQuery', () => {
|
|
|
730
693
|
resource: 'answer'
|
|
731
694
|
}
|
|
732
695
|
};
|
|
733
|
-
|
|
734
|
-
const wrapper = (_ref18) => {
|
|
696
|
+
const wrapper = _ref18 => {
|
|
735
697
|
let {
|
|
736
698
|
children
|
|
737
699
|
} = _ref18;
|
|
@@ -739,28 +701,29 @@ describe('useDataQuery', () => {
|
|
|
739
701
|
data: data
|
|
740
702
|
}, children);
|
|
741
703
|
};
|
|
742
|
-
|
|
743
704
|
const {
|
|
744
705
|
result,
|
|
745
|
-
waitForNextUpdate,
|
|
746
706
|
rerender
|
|
747
|
-
} = (0,
|
|
707
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
748
708
|
wrapper
|
|
749
709
|
});
|
|
750
710
|
const firstRefetch = result.current.refetch;
|
|
751
|
-
|
|
752
|
-
|
|
711
|
+
|
|
712
|
+
// await waitFor(() => {})
|
|
713
|
+
|
|
714
|
+
(0, _react.act)(() => {
|
|
753
715
|
result.current.refetch();
|
|
716
|
+
|
|
754
717
|
/**
|
|
755
718
|
* FIXME: https://github.com/tannerlinsley/react-query/issues/2481
|
|
756
719
|
* This forced rerender is not necessary in the app, just when testing.
|
|
757
720
|
* It is unclear why.
|
|
758
721
|
*/
|
|
759
|
-
|
|
760
722
|
rerender();
|
|
761
723
|
});
|
|
762
|
-
await
|
|
763
|
-
|
|
724
|
+
await (0, _react.waitFor)(() => {
|
|
725
|
+
expect(result.current.refetch).toBe(firstRefetch);
|
|
726
|
+
});
|
|
764
727
|
});
|
|
765
728
|
it('Should return stale data and set loading to true on refetch', async () => {
|
|
766
729
|
const answers = [42, 43];
|
|
@@ -773,8 +736,7 @@ describe('useDataQuery', () => {
|
|
|
773
736
|
resource: 'answer'
|
|
774
737
|
}
|
|
775
738
|
};
|
|
776
|
-
|
|
777
|
-
const wrapper = (_ref19) => {
|
|
739
|
+
const wrapper = _ref19 => {
|
|
778
740
|
let {
|
|
779
741
|
children
|
|
780
742
|
} = _ref19;
|
|
@@ -782,12 +744,10 @@ describe('useDataQuery', () => {
|
|
|
782
744
|
data: data
|
|
783
745
|
}, children);
|
|
784
746
|
};
|
|
785
|
-
|
|
786
747
|
const {
|
|
787
748
|
result,
|
|
788
|
-
waitForNextUpdate,
|
|
789
749
|
rerender
|
|
790
|
-
} = (0,
|
|
750
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query), {
|
|
791
751
|
wrapper
|
|
792
752
|
});
|
|
793
753
|
expect(mockSpy).toHaveBeenCalledTimes(1);
|
|
@@ -795,22 +755,23 @@ describe('useDataQuery', () => {
|
|
|
795
755
|
loading: true,
|
|
796
756
|
called: true
|
|
797
757
|
});
|
|
798
|
-
await
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
758
|
+
await (0, _react.waitFor)(() => {
|
|
759
|
+
expect(result.current).toMatchObject({
|
|
760
|
+
loading: false,
|
|
761
|
+
called: true,
|
|
762
|
+
data: {
|
|
763
|
+
x: 42
|
|
764
|
+
}
|
|
765
|
+
});
|
|
805
766
|
});
|
|
806
|
-
(0,
|
|
767
|
+
(0, _react.act)(() => {
|
|
807
768
|
result.current.refetch();
|
|
769
|
+
|
|
808
770
|
/**
|
|
809
771
|
* FIXME: https://github.com/tannerlinsley/react-query/issues/2481
|
|
810
772
|
* This forced rerender is not necessary in the app, just when testing.
|
|
811
773
|
* It is unclear why.
|
|
812
774
|
*/
|
|
813
|
-
|
|
814
775
|
rerender();
|
|
815
776
|
});
|
|
816
777
|
expect(mockSpy).toHaveBeenCalledTimes(2);
|
|
@@ -822,15 +783,16 @@ describe('useDataQuery', () => {
|
|
|
822
783
|
x: 42
|
|
823
784
|
}
|
|
824
785
|
});
|
|
825
|
-
await
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
786
|
+
await (0, _react.waitFor)(() => {
|
|
787
|
+
expect(mockSpy).toHaveBeenCalledTimes(2);
|
|
788
|
+
expect(result.current).toMatchObject({
|
|
789
|
+
loading: false,
|
|
790
|
+
fetching: false,
|
|
791
|
+
called: true,
|
|
792
|
+
data: {
|
|
793
|
+
x: 43
|
|
794
|
+
}
|
|
795
|
+
});
|
|
834
796
|
});
|
|
835
797
|
});
|
|
836
798
|
it('Should not fetch until refetch has been called if lazy', async () => {
|
|
@@ -843,8 +805,7 @@ describe('useDataQuery', () => {
|
|
|
843
805
|
const data = {
|
|
844
806
|
answer: mockSpy
|
|
845
807
|
};
|
|
846
|
-
|
|
847
|
-
const wrapper = (_ref20) => {
|
|
808
|
+
const wrapper = _ref20 => {
|
|
848
809
|
let {
|
|
849
810
|
children
|
|
850
811
|
} = _ref20;
|
|
@@ -852,11 +813,9 @@ describe('useDataQuery', () => {
|
|
|
852
813
|
data: data
|
|
853
814
|
}, children);
|
|
854
815
|
};
|
|
855
|
-
|
|
856
816
|
const {
|
|
857
|
-
result
|
|
858
|
-
|
|
859
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
817
|
+
result
|
|
818
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
860
819
|
lazy: true
|
|
861
820
|
}), {
|
|
862
821
|
wrapper
|
|
@@ -866,7 +825,7 @@ describe('useDataQuery', () => {
|
|
|
866
825
|
loading: false,
|
|
867
826
|
called: false
|
|
868
827
|
});
|
|
869
|
-
(0,
|
|
828
|
+
(0, _react.act)(() => {
|
|
870
829
|
result.current.refetch();
|
|
871
830
|
});
|
|
872
831
|
expect(mockSpy).toHaveBeenCalledTimes(1);
|
|
@@ -874,13 +833,14 @@ describe('useDataQuery', () => {
|
|
|
874
833
|
loading: true,
|
|
875
834
|
called: true
|
|
876
835
|
});
|
|
877
|
-
await
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
836
|
+
await (0, _react.waitFor)(() => {
|
|
837
|
+
expect(result.current).toMatchObject({
|
|
838
|
+
loading: false,
|
|
839
|
+
called: true,
|
|
840
|
+
data: {
|
|
841
|
+
x: 42
|
|
842
|
+
}
|
|
843
|
+
});
|
|
884
844
|
});
|
|
885
845
|
});
|
|
886
846
|
it('Should call onComplete after a successful refetch', async () => {
|
|
@@ -892,8 +852,7 @@ describe('useDataQuery', () => {
|
|
|
892
852
|
const data = {
|
|
893
853
|
answer: 42
|
|
894
854
|
};
|
|
895
|
-
|
|
896
|
-
const wrapper = (_ref21) => {
|
|
855
|
+
const wrapper = _ref21 => {
|
|
897
856
|
let {
|
|
898
857
|
children
|
|
899
858
|
} = _ref21;
|
|
@@ -901,34 +860,33 @@ describe('useDataQuery', () => {
|
|
|
901
860
|
data: data
|
|
902
861
|
}, children);
|
|
903
862
|
};
|
|
904
|
-
|
|
905
863
|
const onComplete = jest.fn();
|
|
906
864
|
const onError = jest.fn();
|
|
907
865
|
const {
|
|
908
|
-
result
|
|
909
|
-
|
|
910
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
866
|
+
result
|
|
867
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
911
868
|
lazy: true,
|
|
912
869
|
onComplete,
|
|
913
870
|
onError
|
|
914
871
|
}), {
|
|
915
872
|
wrapper
|
|
916
873
|
});
|
|
917
|
-
(0,
|
|
874
|
+
(0, _react.act)(() => {
|
|
918
875
|
result.current.refetch();
|
|
919
876
|
});
|
|
920
|
-
await
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
877
|
+
await (0, _react.waitFor)(() => {
|
|
878
|
+
expect(result.current).toMatchObject({
|
|
879
|
+
loading: false,
|
|
880
|
+
called: true,
|
|
881
|
+
data: {
|
|
882
|
+
x: 42
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
expect(onComplete).toHaveBeenCalledWith({
|
|
925
886
|
x: 42
|
|
926
|
-
}
|
|
927
|
-
|
|
928
|
-
expect(onComplete).toHaveBeenCalledWith({
|
|
929
|
-
x: 42
|
|
887
|
+
});
|
|
888
|
+
expect(onError).not.toHaveBeenCalled();
|
|
930
889
|
});
|
|
931
|
-
expect(onError).not.toHaveBeenCalled();
|
|
932
890
|
});
|
|
933
891
|
it('Should call onError after a failed refetch', async () => {
|
|
934
892
|
const expectedError = new Error('Something went wrong');
|
|
@@ -942,8 +900,7 @@ describe('useDataQuery', () => {
|
|
|
942
900
|
throw expectedError;
|
|
943
901
|
}
|
|
944
902
|
};
|
|
945
|
-
|
|
946
|
-
const wrapper = (_ref22) => {
|
|
903
|
+
const wrapper = _ref22 => {
|
|
947
904
|
let {
|
|
948
905
|
children
|
|
949
906
|
} = _ref22;
|
|
@@ -951,27 +908,26 @@ describe('useDataQuery', () => {
|
|
|
951
908
|
data: data
|
|
952
909
|
}, children);
|
|
953
910
|
};
|
|
954
|
-
|
|
955
911
|
const onComplete = jest.fn();
|
|
956
912
|
const onError = jest.fn();
|
|
957
913
|
const {
|
|
958
|
-
result
|
|
959
|
-
|
|
960
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
914
|
+
result
|
|
915
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
961
916
|
lazy: true,
|
|
962
917
|
onComplete,
|
|
963
918
|
onError
|
|
964
919
|
}), {
|
|
965
920
|
wrapper
|
|
966
921
|
});
|
|
967
|
-
(0,
|
|
922
|
+
(0, _react.act)(() => {
|
|
968
923
|
result.current.refetch();
|
|
969
924
|
});
|
|
970
|
-
await
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
925
|
+
await (0, _react.waitFor)(() => {
|
|
926
|
+
expect(onError).toHaveBeenCalledWith(expectedError);
|
|
927
|
+
expect(onComplete).not.toHaveBeenCalled();
|
|
928
|
+
expect(result.current).toMatchObject({
|
|
929
|
+
error: expectedError
|
|
930
|
+
});
|
|
975
931
|
});
|
|
976
932
|
});
|
|
977
933
|
it('Should refetch when refetch is called with variables that resolve to the same query key', async () => {
|
|
@@ -983,7 +939,7 @@ describe('useDataQuery', () => {
|
|
|
983
939
|
const query = {
|
|
984
940
|
x: {
|
|
985
941
|
resource: 'answer',
|
|
986
|
-
params:
|
|
942
|
+
params: _ref23 => {
|
|
987
943
|
let {
|
|
988
944
|
one,
|
|
989
945
|
two,
|
|
@@ -1001,8 +957,7 @@ describe('useDataQuery', () => {
|
|
|
1001
957
|
const data = {
|
|
1002
958
|
answer: spy
|
|
1003
959
|
};
|
|
1004
|
-
|
|
1005
|
-
const wrapper = (_ref24) => {
|
|
960
|
+
const wrapper = _ref24 => {
|
|
1006
961
|
let {
|
|
1007
962
|
children
|
|
1008
963
|
} = _ref24;
|
|
@@ -1010,35 +965,35 @@ describe('useDataQuery', () => {
|
|
|
1010
965
|
data: data
|
|
1011
966
|
}, children);
|
|
1012
967
|
};
|
|
1013
|
-
|
|
1014
968
|
const {
|
|
1015
|
-
result
|
|
1016
|
-
|
|
1017
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
969
|
+
result
|
|
970
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1018
971
|
variables
|
|
1019
972
|
}), {
|
|
1020
973
|
wrapper
|
|
1021
974
|
});
|
|
1022
|
-
await
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
975
|
+
await (0, _react.waitFor)(() => {
|
|
976
|
+
expect(spy).toHaveBeenCalledTimes(1);
|
|
977
|
+
expect(result.current).toMatchObject({
|
|
978
|
+
loading: false,
|
|
979
|
+
called: true,
|
|
980
|
+
data: {
|
|
981
|
+
x: 42
|
|
982
|
+
}
|
|
983
|
+
});
|
|
1030
984
|
});
|
|
1031
|
-
(0,
|
|
985
|
+
(0, _react.act)(() => {
|
|
1032
986
|
result.current.refetch(variables);
|
|
1033
987
|
});
|
|
1034
|
-
await
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
988
|
+
await (0, _react.waitFor)(() => {
|
|
989
|
+
expect(spy).toHaveBeenCalledTimes(2);
|
|
990
|
+
expect(result.current).toMatchObject({
|
|
991
|
+
loading: false,
|
|
992
|
+
called: true,
|
|
993
|
+
data: {
|
|
994
|
+
x: 42
|
|
995
|
+
}
|
|
996
|
+
});
|
|
1042
997
|
});
|
|
1043
998
|
});
|
|
1044
999
|
it('Should return a promise that resolves with the data on success when refetching and lazy', async () => {
|
|
@@ -1050,8 +1005,7 @@ describe('useDataQuery', () => {
|
|
|
1050
1005
|
const data = {
|
|
1051
1006
|
answer: 42
|
|
1052
1007
|
};
|
|
1053
|
-
|
|
1054
|
-
const wrapper = (_ref25) => {
|
|
1008
|
+
const wrapper = _ref25 => {
|
|
1055
1009
|
let {
|
|
1056
1010
|
children
|
|
1057
1011
|
} = _ref25;
|
|
@@ -1059,30 +1013,29 @@ describe('useDataQuery', () => {
|
|
|
1059
1013
|
data: data
|
|
1060
1014
|
}, children);
|
|
1061
1015
|
};
|
|
1062
|
-
|
|
1063
1016
|
const {
|
|
1064
|
-
result
|
|
1065
|
-
|
|
1066
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1017
|
+
result
|
|
1018
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1067
1019
|
lazy: true
|
|
1068
1020
|
}), {
|
|
1069
1021
|
wrapper
|
|
1070
1022
|
});
|
|
1071
1023
|
let ourPromise;
|
|
1072
|
-
(0,
|
|
1024
|
+
(0, _react.act)(() => {
|
|
1073
1025
|
// This refetch will trigger our own refetch logic as the query is lazy
|
|
1074
1026
|
ourPromise = result.current.refetch();
|
|
1075
1027
|
});
|
|
1076
|
-
await
|
|
1077
|
-
|
|
1078
|
-
x: 42
|
|
1079
|
-
});
|
|
1080
|
-
expect(result.current).toMatchObject({
|
|
1081
|
-
loading: false,
|
|
1082
|
-
called: true,
|
|
1083
|
-
data: {
|
|
1028
|
+
await (0, _react.waitFor)(() => {
|
|
1029
|
+
expect(ourPromise).resolves.toEqual({
|
|
1084
1030
|
x: 42
|
|
1085
|
-
}
|
|
1031
|
+
});
|
|
1032
|
+
expect(result.current).toMatchObject({
|
|
1033
|
+
loading: false,
|
|
1034
|
+
called: true,
|
|
1035
|
+
data: {
|
|
1036
|
+
x: 42
|
|
1037
|
+
}
|
|
1038
|
+
});
|
|
1086
1039
|
});
|
|
1087
1040
|
});
|
|
1088
1041
|
it('Should return a promise that resolves with the data on success when refetching and not lazy', async () => {
|
|
@@ -1094,8 +1047,7 @@ describe('useDataQuery', () => {
|
|
|
1094
1047
|
const data = {
|
|
1095
1048
|
answer: 42
|
|
1096
1049
|
};
|
|
1097
|
-
|
|
1098
|
-
const wrapper = (_ref26) => {
|
|
1050
|
+
const wrapper = _ref26 => {
|
|
1099
1051
|
let {
|
|
1100
1052
|
children
|
|
1101
1053
|
} = _ref26;
|
|
@@ -1103,30 +1055,29 @@ describe('useDataQuery', () => {
|
|
|
1103
1055
|
data: data
|
|
1104
1056
|
}, children);
|
|
1105
1057
|
};
|
|
1106
|
-
|
|
1107
1058
|
const {
|
|
1108
|
-
result
|
|
1109
|
-
|
|
1110
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1059
|
+
result
|
|
1060
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1111
1061
|
lazy: false
|
|
1112
1062
|
}), {
|
|
1113
1063
|
wrapper
|
|
1114
1064
|
});
|
|
1115
1065
|
let reactQueryPromise;
|
|
1116
|
-
(0,
|
|
1066
|
+
(0, _react.act)(() => {
|
|
1117
1067
|
// This refetch will trigger react query's refetch logic as the query is not lazy
|
|
1118
1068
|
reactQueryPromise = result.current.refetch();
|
|
1119
1069
|
});
|
|
1120
|
-
await
|
|
1121
|
-
|
|
1122
|
-
x: 42
|
|
1123
|
-
});
|
|
1124
|
-
expect(result.current).toMatchObject({
|
|
1125
|
-
loading: false,
|
|
1126
|
-
called: true,
|
|
1127
|
-
data: {
|
|
1070
|
+
await (0, _react.waitFor)(() => {
|
|
1071
|
+
expect(reactQueryPromise).resolves.toEqual({
|
|
1128
1072
|
x: 42
|
|
1129
|
-
}
|
|
1073
|
+
});
|
|
1074
|
+
expect(result.current).toMatchObject({
|
|
1075
|
+
loading: false,
|
|
1076
|
+
called: true,
|
|
1077
|
+
data: {
|
|
1078
|
+
x: 42
|
|
1079
|
+
}
|
|
1080
|
+
});
|
|
1130
1081
|
});
|
|
1131
1082
|
});
|
|
1132
1083
|
it('Should return a promise that does not reject on errors when refetching and lazy', async () => {
|
|
@@ -1141,8 +1092,7 @@ describe('useDataQuery', () => {
|
|
|
1141
1092
|
throw expectedError;
|
|
1142
1093
|
}
|
|
1143
1094
|
};
|
|
1144
|
-
|
|
1145
|
-
const wrapper = (_ref27) => {
|
|
1095
|
+
const wrapper = _ref27 => {
|
|
1146
1096
|
let {
|
|
1147
1097
|
children
|
|
1148
1098
|
} = _ref27;
|
|
@@ -1150,24 +1100,23 @@ describe('useDataQuery', () => {
|
|
|
1150
1100
|
data: data
|
|
1151
1101
|
}, children);
|
|
1152
1102
|
};
|
|
1153
|
-
|
|
1154
1103
|
const {
|
|
1155
|
-
result
|
|
1156
|
-
|
|
1157
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1104
|
+
result
|
|
1105
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1158
1106
|
lazy: true
|
|
1159
1107
|
}), {
|
|
1160
1108
|
wrapper
|
|
1161
1109
|
});
|
|
1162
1110
|
let ourPromise;
|
|
1163
|
-
(0,
|
|
1111
|
+
(0, _react.act)(() => {
|
|
1164
1112
|
// This refetch will trigger our own refetch logic as the query is lazy
|
|
1165
1113
|
ourPromise = result.current.refetch();
|
|
1166
1114
|
});
|
|
1167
|
-
await
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1115
|
+
await (0, _react.waitFor)(() => {
|
|
1116
|
+
expect(ourPromise).resolves.toBeUndefined();
|
|
1117
|
+
expect(result.current).toMatchObject({
|
|
1118
|
+
error: expectedError
|
|
1119
|
+
});
|
|
1171
1120
|
});
|
|
1172
1121
|
});
|
|
1173
1122
|
it('Should return a promise that does not reject on errors when refetching and not lazy', async () => {
|
|
@@ -1182,8 +1131,7 @@ describe('useDataQuery', () => {
|
|
|
1182
1131
|
throw expectedError;
|
|
1183
1132
|
}
|
|
1184
1133
|
};
|
|
1185
|
-
|
|
1186
|
-
const wrapper = (_ref28) => {
|
|
1134
|
+
const wrapper = _ref28 => {
|
|
1187
1135
|
let {
|
|
1188
1136
|
children
|
|
1189
1137
|
} = _ref28;
|
|
@@ -1191,24 +1139,23 @@ describe('useDataQuery', () => {
|
|
|
1191
1139
|
data: data
|
|
1192
1140
|
}, children);
|
|
1193
1141
|
};
|
|
1194
|
-
|
|
1195
1142
|
const {
|
|
1196
|
-
result
|
|
1197
|
-
|
|
1198
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1143
|
+
result
|
|
1144
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1199
1145
|
lazy: false
|
|
1200
1146
|
}), {
|
|
1201
1147
|
wrapper
|
|
1202
1148
|
});
|
|
1203
1149
|
let reactQueryPromise;
|
|
1204
|
-
(0,
|
|
1150
|
+
(0, _react.act)(() => {
|
|
1205
1151
|
// This refetch will trigger react query's refetch logic as the query is not lazy
|
|
1206
1152
|
reactQueryPromise = result.current.refetch();
|
|
1207
1153
|
});
|
|
1208
|
-
await
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1154
|
+
await (0, _react.waitFor)(() => {
|
|
1155
|
+
expect(reactQueryPromise).resolves.toBeUndefined();
|
|
1156
|
+
expect(result.current).toMatchObject({
|
|
1157
|
+
error: expectedError
|
|
1158
|
+
});
|
|
1212
1159
|
});
|
|
1213
1160
|
});
|
|
1214
1161
|
it('Should accept new variables from refetch', async () => {
|
|
@@ -1219,7 +1166,7 @@ describe('useDataQuery', () => {
|
|
|
1219
1166
|
const query = {
|
|
1220
1167
|
x: {
|
|
1221
1168
|
resource: 'answer',
|
|
1222
|
-
id:
|
|
1169
|
+
id: _ref29 => {
|
|
1223
1170
|
let {
|
|
1224
1171
|
id
|
|
1225
1172
|
} = _ref29;
|
|
@@ -1231,11 +1178,9 @@ describe('useDataQuery', () => {
|
|
|
1231
1178
|
let {
|
|
1232
1179
|
id
|
|
1233
1180
|
} = _ref30;
|
|
1234
|
-
|
|
1235
1181
|
switch (id) {
|
|
1236
1182
|
case one:
|
|
1237
1183
|
return Promise.resolve(resultOne);
|
|
1238
|
-
|
|
1239
1184
|
case two:
|
|
1240
1185
|
return Promise.resolve(resultTwo);
|
|
1241
1186
|
}
|
|
@@ -1243,8 +1188,7 @@ describe('useDataQuery', () => {
|
|
|
1243
1188
|
const data = {
|
|
1244
1189
|
answer: mockSpy
|
|
1245
1190
|
};
|
|
1246
|
-
|
|
1247
|
-
const wrapper = (_ref31) => {
|
|
1191
|
+
const wrapper = _ref31 => {
|
|
1248
1192
|
let {
|
|
1249
1193
|
children
|
|
1250
1194
|
} = _ref31;
|
|
@@ -1252,7 +1196,6 @@ describe('useDataQuery', () => {
|
|
|
1252
1196
|
data: data
|
|
1253
1197
|
}, children);
|
|
1254
1198
|
};
|
|
1255
|
-
|
|
1256
1199
|
const initialProps = {
|
|
1257
1200
|
query,
|
|
1258
1201
|
options: {
|
|
@@ -1262,29 +1205,30 @@ describe('useDataQuery', () => {
|
|
|
1262
1205
|
}
|
|
1263
1206
|
};
|
|
1264
1207
|
const {
|
|
1265
|
-
result
|
|
1266
|
-
|
|
1267
|
-
} = (0, _reactHooks.renderHook)(props => (0, _useDataQuery.useDataQuery)(props.query, props.options), {
|
|
1208
|
+
result
|
|
1209
|
+
} = (0, _react.renderHook)(props => (0, _useDataQuery.useDataQuery)(props.query, props.options), {
|
|
1268
1210
|
wrapper,
|
|
1269
1211
|
initialProps
|
|
1270
1212
|
});
|
|
1271
|
-
await
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1213
|
+
await (0, _react.waitFor)(() => {
|
|
1214
|
+
expect(result.current).toMatchObject({
|
|
1215
|
+
data: {
|
|
1216
|
+
x: resultOne
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1276
1219
|
});
|
|
1277
|
-
(0,
|
|
1220
|
+
(0, _react.act)(() => {
|
|
1278
1221
|
result.current.refetch({
|
|
1279
1222
|
id: two
|
|
1280
1223
|
});
|
|
1281
1224
|
});
|
|
1282
|
-
await
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1225
|
+
await (0, _react.waitFor)(() => {
|
|
1226
|
+
expect(mockSpy).toHaveBeenCalledTimes(2);
|
|
1227
|
+
expect(result.current).toMatchObject({
|
|
1228
|
+
data: {
|
|
1229
|
+
x: resultTwo
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1288
1232
|
});
|
|
1289
1233
|
});
|
|
1290
1234
|
it('Should merge new variables from refetch with the existing variables', async () => {
|
|
@@ -1300,7 +1244,7 @@ describe('useDataQuery', () => {
|
|
|
1300
1244
|
const query = {
|
|
1301
1245
|
x: {
|
|
1302
1246
|
resource: 'answer',
|
|
1303
|
-
params:
|
|
1247
|
+
params: _ref32 => {
|
|
1304
1248
|
let {
|
|
1305
1249
|
one,
|
|
1306
1250
|
two,
|
|
@@ -1318,8 +1262,7 @@ describe('useDataQuery', () => {
|
|
|
1318
1262
|
const data = {
|
|
1319
1263
|
answer: mockSpy
|
|
1320
1264
|
};
|
|
1321
|
-
|
|
1322
|
-
const wrapper = (_ref33) => {
|
|
1265
|
+
const wrapper = _ref33 => {
|
|
1323
1266
|
let {
|
|
1324
1267
|
children
|
|
1325
1268
|
} = _ref33;
|
|
@@ -1327,28 +1270,29 @@ describe('useDataQuery', () => {
|
|
|
1327
1270
|
data: data
|
|
1328
1271
|
}, children);
|
|
1329
1272
|
};
|
|
1330
|
-
|
|
1331
1273
|
const {
|
|
1332
|
-
result
|
|
1333
|
-
|
|
1334
|
-
} = (0, _reactHooks.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1274
|
+
result
|
|
1275
|
+
} = (0, _react.renderHook)(() => (0, _useDataQuery.useDataQuery)(query, {
|
|
1335
1276
|
variables: initialVariables
|
|
1336
1277
|
}), {
|
|
1337
1278
|
wrapper
|
|
1338
1279
|
});
|
|
1339
|
-
await
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1280
|
+
await (0, _react.waitFor)(() => {
|
|
1281
|
+
expect(mockSpy).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({
|
|
1282
|
+
params: initialVariables
|
|
1283
|
+
}), expect.anything());
|
|
1284
|
+
});
|
|
1285
|
+
(0, _react.act)(() => {
|
|
1344
1286
|
result.current.refetch(newVariables);
|
|
1345
1287
|
});
|
|
1346
|
-
await
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1288
|
+
await (0, _react.waitFor)(() => {
|
|
1289
|
+
expect(mockSpy).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({
|
|
1290
|
+
params: {
|
|
1291
|
+
...initialVariables,
|
|
1292
|
+
...newVariables
|
|
1293
|
+
}
|
|
1294
|
+
}), expect.anything());
|
|
1295
|
+
});
|
|
1352
1296
|
});
|
|
1353
1297
|
});
|
|
1354
1298
|
});
|