@trackunit/react-core-contexts-test 0.1.126 → 0.1.127
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/HookRenderer.cjs.js +10 -529
- package/HookRenderer.esm.js +12 -524
- package/index.cjs.js +7 -5
- package/index.cjs2.js +19 -43222
- package/index.esm.js +8 -6
- package/index.esm2.js +10 -43187
- package/package.json +10 -10
package/HookRenderer.cjs.js
CHANGED
|
@@ -2,536 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
var index = require('./index.cjs2.js');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var ReactDOMClient = require('react-dom/client');
|
|
8
|
-
var testUtils$1 = require('react-dom/test-utils');
|
|
9
|
-
require('util');
|
|
5
|
+
var react = require('@testing-library/react');
|
|
6
|
+
var pure = require('@testing-library/react/pure');
|
|
10
7
|
require('@trackunit/react-core-hooks');
|
|
8
|
+
require('lodash');
|
|
11
9
|
require('react-router-dom');
|
|
10
|
+
require('@apollo/client');
|
|
11
|
+
require('@apollo/client/link/error');
|
|
12
|
+
require('@apollo/client/testing');
|
|
12
13
|
require('@trackunit/react-core-contexts-api');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
17
|
-
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
18
|
-
var ReactDOMClient__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOMClient);
|
|
19
|
-
var testUtils__default = /*#__PURE__*/_interopDefaultLegacy(testUtils$1);
|
|
20
|
-
|
|
21
|
-
var pure$1 = {};
|
|
22
|
-
|
|
23
|
-
var interopRequireDefault = {exports: {}};
|
|
24
|
-
|
|
25
|
-
(function (module) {
|
|
26
|
-
function _interopRequireDefault(obj) {
|
|
27
|
-
return obj && obj.__esModule ? obj : {
|
|
28
|
-
"default": obj
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
32
|
-
}(interopRequireDefault));
|
|
33
|
-
|
|
34
|
-
var require$$4 = /*@__PURE__*/index.getAugmentedNamespace(index.dom_esm);
|
|
35
|
-
|
|
36
|
-
var actCompat = {};
|
|
37
|
-
|
|
38
|
-
Object.defineProperty(actCompat, "__esModule", {
|
|
39
|
-
value: true
|
|
40
|
-
});
|
|
41
|
-
actCompat.default = void 0;
|
|
42
|
-
actCompat.getIsReactActEnvironment = getIsReactActEnvironment;
|
|
43
|
-
actCompat.setReactActEnvironment = setIsReactActEnvironment;
|
|
44
|
-
|
|
45
|
-
var testUtils = _interopRequireWildcard(testUtils__default["default"]);
|
|
46
|
-
|
|
47
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
48
|
-
|
|
49
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
50
|
-
|
|
51
|
-
const domAct = testUtils.act;
|
|
52
|
-
|
|
53
|
-
function getGlobalThis() {
|
|
54
|
-
/* istanbul ignore else */
|
|
55
|
-
if (typeof globalThis !== 'undefined') {
|
|
56
|
-
return globalThis;
|
|
57
|
-
}
|
|
58
|
-
/* istanbul ignore next */
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (typeof self !== 'undefined') {
|
|
62
|
-
return self;
|
|
63
|
-
}
|
|
64
|
-
/* istanbul ignore next */
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (typeof window !== 'undefined') {
|
|
68
|
-
return window;
|
|
69
|
-
}
|
|
70
|
-
/* istanbul ignore next */
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
if (typeof index.commonjsGlobal !== 'undefined') {
|
|
74
|
-
return index.commonjsGlobal;
|
|
75
|
-
}
|
|
76
|
-
/* istanbul ignore next */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
throw new Error('unable to locate global object');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function setIsReactActEnvironment(isReactActEnvironment) {
|
|
83
|
-
getGlobalThis().IS_REACT_ACT_ENVIRONMENT = isReactActEnvironment;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getIsReactActEnvironment() {
|
|
87
|
-
return getGlobalThis().IS_REACT_ACT_ENVIRONMENT;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function withGlobalActEnvironment(actImplementation) {
|
|
91
|
-
return callback => {
|
|
92
|
-
const previousActEnvironment = getIsReactActEnvironment();
|
|
93
|
-
setIsReactActEnvironment(true);
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
// The return value of `act` is always a thenable.
|
|
97
|
-
let callbackNeedsToBeAwaited = false;
|
|
98
|
-
const actResult = actImplementation(() => {
|
|
99
|
-
const result = callback();
|
|
100
|
-
|
|
101
|
-
if (result !== null && typeof result === 'object' && typeof result.then === 'function') {
|
|
102
|
-
callbackNeedsToBeAwaited = true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return result;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (callbackNeedsToBeAwaited) {
|
|
109
|
-
const thenable = actResult;
|
|
110
|
-
return {
|
|
111
|
-
then: (resolve, reject) => {
|
|
112
|
-
thenable.then(returnValue => {
|
|
113
|
-
setIsReactActEnvironment(previousActEnvironment);
|
|
114
|
-
resolve(returnValue);
|
|
115
|
-
}, error => {
|
|
116
|
-
setIsReactActEnvironment(previousActEnvironment);
|
|
117
|
-
reject(error);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
} else {
|
|
122
|
-
setIsReactActEnvironment(previousActEnvironment);
|
|
123
|
-
return actResult;
|
|
124
|
-
}
|
|
125
|
-
} catch (error) {
|
|
126
|
-
// Can't be a `finally {}` block since we don't know if we have to immediately restore IS_REACT_ACT_ENVIRONMENT
|
|
127
|
-
// or if we have to await the callback first.
|
|
128
|
-
setIsReactActEnvironment(previousActEnvironment);
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const act = withGlobalActEnvironment(domAct);
|
|
135
|
-
var _default = act;
|
|
136
|
-
/* eslint no-console:0 */
|
|
137
|
-
|
|
138
|
-
actCompat.default = _default;
|
|
139
|
-
|
|
140
|
-
var fireEvent$1 = {};
|
|
141
|
-
|
|
142
|
-
Object.defineProperty(fireEvent$1, "__esModule", {
|
|
143
|
-
value: true
|
|
144
|
-
});
|
|
145
|
-
fireEvent$1.fireEvent = void 0;
|
|
146
|
-
|
|
147
|
-
var _dom = require$$4;
|
|
148
|
-
|
|
149
|
-
// react-testing-library's version of fireEvent will call
|
|
150
|
-
// dom-testing-library's version of fireEvent. The reason
|
|
151
|
-
// we make this distinction however is because we have
|
|
152
|
-
// a few extra events that work a bit differently
|
|
153
|
-
const fireEvent = (...args) => (0, _dom.fireEvent)(...args);
|
|
154
|
-
|
|
155
|
-
fireEvent$1.fireEvent = fireEvent;
|
|
156
|
-
Object.keys(_dom.fireEvent).forEach(key => {
|
|
157
|
-
fireEvent[key] = (...args) => _dom.fireEvent[key](...args);
|
|
158
|
-
}); // React event system tracks native mouseOver/mouseOut events for
|
|
159
|
-
// running onMouseEnter/onMouseLeave handlers
|
|
160
|
-
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/EnterLeaveEventPlugin.js#L24-L31
|
|
161
|
-
|
|
162
|
-
const mouseEnter = fireEvent.mouseEnter;
|
|
163
|
-
const mouseLeave = fireEvent.mouseLeave;
|
|
164
|
-
|
|
165
|
-
fireEvent.mouseEnter = (...args) => {
|
|
166
|
-
mouseEnter(...args);
|
|
167
|
-
return fireEvent.mouseOver(...args);
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
fireEvent.mouseLeave = (...args) => {
|
|
171
|
-
mouseLeave(...args);
|
|
172
|
-
return fireEvent.mouseOut(...args);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const pointerEnter = fireEvent.pointerEnter;
|
|
176
|
-
const pointerLeave = fireEvent.pointerLeave;
|
|
177
|
-
|
|
178
|
-
fireEvent.pointerEnter = (...args) => {
|
|
179
|
-
pointerEnter(...args);
|
|
180
|
-
return fireEvent.pointerOver(...args);
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
fireEvent.pointerLeave = (...args) => {
|
|
184
|
-
pointerLeave(...args);
|
|
185
|
-
return fireEvent.pointerOut(...args);
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
const select = fireEvent.select;
|
|
189
|
-
|
|
190
|
-
fireEvent.select = (node, init) => {
|
|
191
|
-
select(node, init); // React tracks this event only on focused inputs
|
|
192
|
-
|
|
193
|
-
node.focus(); // React creates this event when one of the following native events happens
|
|
194
|
-
// - contextMenu
|
|
195
|
-
// - mouseUp
|
|
196
|
-
// - dragEnd
|
|
197
|
-
// - keyUp
|
|
198
|
-
// - keyDown
|
|
199
|
-
// so we can use any here
|
|
200
|
-
// @link https://github.com/facebook/react/blob/b87aabdfe1b7461e7331abb3601d9e6bb27544bc/packages/react-dom/src/events/SelectEventPlugin.js#L203-L224
|
|
201
|
-
|
|
202
|
-
fireEvent.keyUp(node, init);
|
|
203
|
-
}; // React event system tracks native focusout/focusin events for
|
|
204
|
-
// running blur/focus handlers
|
|
205
|
-
// @link https://github.com/facebook/react/pull/19186
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const blur = fireEvent.blur;
|
|
209
|
-
const focus = fireEvent.focus;
|
|
210
|
-
|
|
211
|
-
fireEvent.blur = (...args) => {
|
|
212
|
-
fireEvent.focusOut(...args);
|
|
213
|
-
return blur(...args);
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
fireEvent.focus = (...args) => {
|
|
217
|
-
fireEvent.focusIn(...args);
|
|
218
|
-
return focus(...args);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
(function (exports) {
|
|
222
|
-
|
|
223
|
-
var _interopRequireDefault = interopRequireDefault.exports;
|
|
224
|
-
|
|
225
|
-
Object.defineProperty(exports, "__esModule", {
|
|
226
|
-
value: true
|
|
227
|
-
});
|
|
228
|
-
var _exportNames = {
|
|
229
|
-
render: true,
|
|
230
|
-
renderHook: true,
|
|
231
|
-
cleanup: true,
|
|
232
|
-
act: true,
|
|
233
|
-
fireEvent: true
|
|
234
|
-
};
|
|
235
|
-
Object.defineProperty(exports, "act", {
|
|
236
|
-
enumerable: true,
|
|
237
|
-
get: function () {
|
|
238
|
-
return _actCompat.default;
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
exports.cleanup = cleanup;
|
|
242
|
-
Object.defineProperty(exports, "fireEvent", {
|
|
243
|
-
enumerable: true,
|
|
244
|
-
get: function () {
|
|
245
|
-
return _fireEvent.fireEvent;
|
|
246
|
-
}
|
|
247
|
-
});
|
|
248
|
-
exports.render = render;
|
|
249
|
-
exports.renderHook = renderHook;
|
|
250
|
-
|
|
251
|
-
var React = _interopRequireWildcard(React__default["default"]);
|
|
252
|
-
|
|
253
|
-
var _reactDom = _interopRequireDefault(ReactDOM__default["default"]);
|
|
254
|
-
|
|
255
|
-
var ReactDOMClient = _interopRequireWildcard(ReactDOMClient__default["default"]);
|
|
256
|
-
|
|
257
|
-
var _dom = require$$4;
|
|
258
|
-
|
|
259
|
-
Object.keys(_dom).forEach(function (key) {
|
|
260
|
-
if (key === "default" || key === "__esModule") return;
|
|
261
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
262
|
-
if (key in exports && exports[key] === _dom[key]) return;
|
|
263
|
-
Object.defineProperty(exports, key, {
|
|
264
|
-
enumerable: true,
|
|
265
|
-
get: function () {
|
|
266
|
-
return _dom[key];
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
var _actCompat = _interopRequireWildcard(actCompat);
|
|
272
|
-
|
|
273
|
-
var _fireEvent = fireEvent$1;
|
|
274
|
-
|
|
275
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
276
|
-
|
|
277
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
278
|
-
|
|
279
|
-
(0, _dom.configure)({
|
|
280
|
-
unstable_advanceTimersWrapper: cb => {
|
|
281
|
-
return (0, _actCompat.default)(cb);
|
|
282
|
-
},
|
|
283
|
-
// We just want to run `waitFor` without IS_REACT_ACT_ENVIRONMENT
|
|
284
|
-
// But that's not necessarily how `asyncWrapper` is used since it's a public method.
|
|
285
|
-
// Let's just hope nobody else is using it.
|
|
286
|
-
asyncWrapper: async cb => {
|
|
287
|
-
const previousActEnvironment = (0, _actCompat.getIsReactActEnvironment)();
|
|
288
|
-
(0, _actCompat.setReactActEnvironment)(false);
|
|
289
|
-
|
|
290
|
-
try {
|
|
291
|
-
return await cb();
|
|
292
|
-
} finally {
|
|
293
|
-
(0, _actCompat.setReactActEnvironment)(previousActEnvironment);
|
|
294
|
-
}
|
|
295
|
-
},
|
|
296
|
-
eventWrapper: cb => {
|
|
297
|
-
let result;
|
|
298
|
-
(0, _actCompat.default)(() => {
|
|
299
|
-
result = cb();
|
|
300
|
-
});
|
|
301
|
-
return result;
|
|
302
|
-
}
|
|
303
|
-
}); // Ideally we'd just use a WeakMap where containers are keys and roots are values.
|
|
304
|
-
// We use two variables so that we can bail out in constant time when we render with a new container (most common use case)
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* @type {Set<import('react-dom').Container>}
|
|
308
|
-
*/
|
|
309
|
-
|
|
310
|
-
const mountedContainers = new Set();
|
|
311
|
-
/**
|
|
312
|
-
* @type Array<{container: import('react-dom').Container, root: ReturnType<typeof createConcurrentRoot>}>
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
const mountedRootEntries = [];
|
|
316
|
-
|
|
317
|
-
function createConcurrentRoot(container, {
|
|
318
|
-
hydrate,
|
|
319
|
-
ui,
|
|
320
|
-
wrapper: WrapperComponent
|
|
321
|
-
}) {
|
|
322
|
-
let root;
|
|
323
|
-
|
|
324
|
-
if (hydrate) {
|
|
325
|
-
(0, _actCompat.default)(() => {
|
|
326
|
-
root = ReactDOMClient.hydrateRoot(container, WrapperComponent ? /*#__PURE__*/React.createElement(WrapperComponent, null, ui) : ui);
|
|
327
|
-
});
|
|
328
|
-
} else {
|
|
329
|
-
root = ReactDOMClient.createRoot(container);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return {
|
|
333
|
-
hydrate() {
|
|
334
|
-
/* istanbul ignore if */
|
|
335
|
-
if (!hydrate) {
|
|
336
|
-
throw new Error('Attempted to hydrate a non-hydrateable root. This is a bug in `@testing-library/react`.');
|
|
337
|
-
} // Nothing to do since hydration happens when creating the root object.
|
|
338
|
-
|
|
339
|
-
},
|
|
340
|
-
|
|
341
|
-
render(element) {
|
|
342
|
-
root.render(element);
|
|
343
|
-
},
|
|
344
|
-
|
|
345
|
-
unmount() {
|
|
346
|
-
root.unmount();
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
};
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
function createLegacyRoot(container) {
|
|
353
|
-
return {
|
|
354
|
-
hydrate(element) {
|
|
355
|
-
_reactDom.default.hydrate(element, container);
|
|
356
|
-
},
|
|
357
|
-
|
|
358
|
-
render(element) {
|
|
359
|
-
_reactDom.default.render(element, container);
|
|
360
|
-
},
|
|
361
|
-
|
|
362
|
-
unmount() {
|
|
363
|
-
_reactDom.default.unmountComponentAtNode(container);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function renderRoot(ui, {
|
|
370
|
-
baseElement,
|
|
371
|
-
container,
|
|
372
|
-
hydrate,
|
|
373
|
-
queries,
|
|
374
|
-
root,
|
|
375
|
-
wrapper: WrapperComponent
|
|
376
|
-
}) {
|
|
377
|
-
const wrapUiIfNeeded = innerElement => WrapperComponent ? /*#__PURE__*/React.createElement(WrapperComponent, null, innerElement) : innerElement;
|
|
378
|
-
|
|
379
|
-
(0, _actCompat.default)(() => {
|
|
380
|
-
if (hydrate) {
|
|
381
|
-
root.hydrate(wrapUiIfNeeded(ui), container);
|
|
382
|
-
} else {
|
|
383
|
-
root.render(wrapUiIfNeeded(ui), container);
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
return {
|
|
387
|
-
container,
|
|
388
|
-
baseElement,
|
|
389
|
-
debug: (el = baseElement, maxLength, options) => Array.isArray(el) ? // eslint-disable-next-line no-console
|
|
390
|
-
el.forEach(e => console.log((0, _dom.prettyDOM)(e, maxLength, options))) : // eslint-disable-next-line no-console,
|
|
391
|
-
console.log((0, _dom.prettyDOM)(el, maxLength, options)),
|
|
392
|
-
unmount: () => {
|
|
393
|
-
(0, _actCompat.default)(() => {
|
|
394
|
-
root.unmount();
|
|
395
|
-
});
|
|
396
|
-
},
|
|
397
|
-
rerender: rerenderUi => {
|
|
398
|
-
renderRoot(wrapUiIfNeeded(rerenderUi), {
|
|
399
|
-
container,
|
|
400
|
-
baseElement,
|
|
401
|
-
root
|
|
402
|
-
}); // Intentionally do not return anything to avoid unnecessarily complicating the API.
|
|
403
|
-
// folks can use all the same utilities we return in the first place that are bound to the container
|
|
404
|
-
},
|
|
405
|
-
asFragment: () => {
|
|
406
|
-
/* istanbul ignore else (old jsdom limitation) */
|
|
407
|
-
if (typeof document.createRange === 'function') {
|
|
408
|
-
return document.createRange().createContextualFragment(container.innerHTML);
|
|
409
|
-
} else {
|
|
410
|
-
const template = document.createElement('template');
|
|
411
|
-
template.innerHTML = container.innerHTML;
|
|
412
|
-
return template.content;
|
|
413
|
-
}
|
|
414
|
-
},
|
|
415
|
-
...(0, _dom.getQueriesForElement)(baseElement, queries)
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
function render(ui, {
|
|
420
|
-
container,
|
|
421
|
-
baseElement = container,
|
|
422
|
-
legacyRoot = false,
|
|
423
|
-
queries,
|
|
424
|
-
hydrate = false,
|
|
425
|
-
wrapper
|
|
426
|
-
} = {}) {
|
|
427
|
-
if (!baseElement) {
|
|
428
|
-
// default to document.body instead of documentElement to avoid output of potentially-large
|
|
429
|
-
// head elements (such as JSS style blocks) in debug output
|
|
430
|
-
baseElement = document.body;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
if (!container) {
|
|
434
|
-
container = baseElement.appendChild(document.createElement('div'));
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
let root; // eslint-disable-next-line no-negated-condition -- we want to map the evolution of this over time. The root is created first. Only later is it re-used so we don't want to read the case that happens later first.
|
|
438
|
-
|
|
439
|
-
if (!mountedContainers.has(container)) {
|
|
440
|
-
const createRootImpl = legacyRoot ? createLegacyRoot : createConcurrentRoot;
|
|
441
|
-
root = createRootImpl(container, {
|
|
442
|
-
hydrate,
|
|
443
|
-
ui,
|
|
444
|
-
wrapper
|
|
445
|
-
});
|
|
446
|
-
mountedRootEntries.push({
|
|
447
|
-
container,
|
|
448
|
-
root
|
|
449
|
-
}); // we'll add it to the mounted containers regardless of whether it's actually
|
|
450
|
-
// added to document.body so the cleanup method works regardless of whether
|
|
451
|
-
// they're passing us a custom container or not.
|
|
452
|
-
|
|
453
|
-
mountedContainers.add(container);
|
|
454
|
-
} else {
|
|
455
|
-
mountedRootEntries.forEach(rootEntry => {
|
|
456
|
-
// Else is unreachable since `mountedContainers` has the `container`.
|
|
457
|
-
// Only reachable if one would accidentally add the container to `mountedContainers` but not the root to `mountedRootEntries`
|
|
458
|
-
|
|
459
|
-
/* istanbul ignore else */
|
|
460
|
-
if (rootEntry.container === container) {
|
|
461
|
-
root = rootEntry.root;
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return renderRoot(ui, {
|
|
467
|
-
container,
|
|
468
|
-
baseElement,
|
|
469
|
-
queries,
|
|
470
|
-
hydrate,
|
|
471
|
-
wrapper,
|
|
472
|
-
root
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function cleanup() {
|
|
477
|
-
mountedRootEntries.forEach(({
|
|
478
|
-
root,
|
|
479
|
-
container
|
|
480
|
-
}) => {
|
|
481
|
-
(0, _actCompat.default)(() => {
|
|
482
|
-
root.unmount();
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
if (container.parentNode === document.body) {
|
|
486
|
-
document.body.removeChild(container);
|
|
487
|
-
}
|
|
488
|
-
});
|
|
489
|
-
mountedRootEntries.length = 0;
|
|
490
|
-
mountedContainers.clear();
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
function renderHook(renderCallback, options = {}) {
|
|
494
|
-
const {
|
|
495
|
-
initialProps,
|
|
496
|
-
...renderOptions
|
|
497
|
-
} = options;
|
|
498
|
-
const result = /*#__PURE__*/React.createRef();
|
|
499
|
-
|
|
500
|
-
function TestComponent({
|
|
501
|
-
renderCallbackProps
|
|
502
|
-
}) {
|
|
503
|
-
const pendingResult = renderCallback(renderCallbackProps);
|
|
504
|
-
React.useEffect(() => {
|
|
505
|
-
result.current = pendingResult;
|
|
506
|
-
});
|
|
507
|
-
return null;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
const {
|
|
511
|
-
rerender: baseRerender,
|
|
512
|
-
unmount
|
|
513
|
-
} = render( /*#__PURE__*/React.createElement(TestComponent, {
|
|
514
|
-
renderCallbackProps: initialProps
|
|
515
|
-
}), renderOptions);
|
|
516
|
-
|
|
517
|
-
function rerender(rerenderCallbackProps) {
|
|
518
|
-
return baseRerender( /*#__PURE__*/React.createElement(TestComponent, {
|
|
519
|
-
renderCallbackProps: rerenderCallbackProps
|
|
520
|
-
}));
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
return {
|
|
524
|
-
result,
|
|
525
|
-
rerender,
|
|
526
|
-
unmount
|
|
527
|
-
};
|
|
528
|
-
} // just re-export everything from dom-testing-library
|
|
529
|
-
|
|
530
|
-
/* eslint func-name-matching:0 */
|
|
531
|
-
}(pure$1));
|
|
532
|
-
|
|
533
|
-
// makes it so people can import from '@testing-library/react/pure'
|
|
534
|
-
var pure = pure$1;
|
|
14
|
+
require('react');
|
|
15
|
+
require('graphql');
|
|
535
16
|
|
|
536
17
|
/**
|
|
537
18
|
* This is a wrapper around the react testing library renderHook function.
|
|
@@ -550,10 +31,10 @@ const reactHooksRenderHook = (callback, getMockedCompositionRoot) => index.__awa
|
|
|
550
31
|
let renderedHook;
|
|
551
32
|
// This is added here to make storybook work and to ensure the right act is loaded for hooks.
|
|
552
33
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
553
|
-
yield
|
|
34
|
+
yield react.act(() => index.__awaiter(void 0, void 0, void 0, function* () {
|
|
554
35
|
renderedHook = yield pure.renderHook(callback, { wrapper });
|
|
555
36
|
}));
|
|
556
|
-
yield
|
|
37
|
+
yield react.act(() => index.__awaiter(void 0, void 0, void 0, function* () {
|
|
557
38
|
yield index.flushPromises();
|
|
558
39
|
}));
|
|
559
40
|
return renderedHook;
|