Skip to content
This repository was archived by the owner on Dec 31, 2024. It is now read-only.

Commit 1c3a795

Browse files
committed
patch react dom for better error message
1 parent 572295d commit 1c3a795

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ TypeError: Cannot read property 'createEvent' of null
2626
at processImmediate (internal/timers.js:464:21)
2727
```
2828

29+
To find the test that this error originates from easier, apply this patch
30+
31+
```bash
32+
patch node_modules/react-dom/cjs/react-dom-test-utils.development.js < react-dom-test-utils.development.js.patch
33+
yarn test
34+
```
35+
36+
And now you get something like
37+
38+
```bash
39+
RUNS ./test.js
40+
/Users/user/Documents/repos/react-testing-library-error-repro/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1010
41+
throw ex || err;
42+
^
43+
44+
Test Failed: /Users/user/Documents/repos/react-testing-library-error-repro/test.js::it
45+
at Object.act (/Users/user/Documents/repos/react-testing-library-error-repro/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1072:16)
46+
at /Users/user/Documents/repos/react-testing-library-error-repro/test.js:41:30
47+
at processTicksAndRejections (node:internal/process/task_queues:95:5)
48+
```
49+
2950
Environment:
3051
```bash
3152
$ npx envinfo
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--- node_modules/react-dom/cjs/react-dom-test-utils.development.js 2022-06-22 09:44:47.000000000 -0400
2+
+++ react-dom-test-utils.development.js 2022-06-22 09:44:53.000000000 -0400
3+
@@ -996,15 +996,19 @@
4+
return didFlushWork;
5+
};
6+
7+
-function flushWorkAndMicroTasks(onDone) {
8+
+function flushWorkAndMicroTasks(onDone, ex) {
9+
try {
10+
flushWork();
11+
enqueueTask(function () {
12+
+ try {
13+
if (flushWork()) {
14+
flushWorkAndMicroTasks(onDone);
15+
} else {
16+
onDone();
17+
}
18+
+ } catch (err) {
19+
+ throw ex || err;
20+
+ }
21+
});
22+
} catch (err) {
23+
onDone(err);
24+
@@ -1064,6 +1068,9 @@
25+
// effects and microtasks in a loop until flushPassiveEffects() === false,
26+
// and cleans up
27+
28+
+ const {testPath, currentTestName} = expect.getState();
29+
+ const ex = new Error(`${testPath}::${currentTestName}`);
30+
+ ex.name = 'Test Failed';
31+
32+
return {
33+
then: function (resolve, reject) {
34+
@@ -1085,7 +1092,7 @@
35+
} else {
36+
resolve();
37+
}
38+
- });
39+
+ }, ex);
40+
}, function (err) {
41+
onDone();
42+
reject(err);

0 commit comments

Comments
 (0)