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