Skip to content

Commit 4f8ffec

Browse files
authored
Rejct toWarnDev if given callback throws (#26003)
## Summary Should unblock #25970 If the callback for `toWarnDev` was `async` and threw, we didn't ultimately reject the await Promise from the matcher. This resulted in tests failing even though the failure was expected due to a test gate. ## How did you test this change? - [x] tested in #25970 with `yarn test --r=stable --env=development packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js --watch` - [x] `yarn test` - [x] CI
1 parent 0e31dd0 commit 4f8ffec

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

scripts/jest/matchers/toWarnDev.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,20 @@ const createMatcherFor = (consoleMethod, matcherName) =>
270270
// Once `act(async () => {}).then(() => {}).then(() => {})` works
271271
// we can just return `result.then(onFinally, error => ...)`
272272
returnPromise = new Promise((resolve, reject) => {
273-
result.then(
274-
() => {
275-
resolve(onFinally());
276-
},
277-
error => {
278-
caughtError = error;
279-
return resolve(onFinally());
280-
}
281-
);
273+
result
274+
.then(
275+
() => {
276+
resolve(onFinally());
277+
},
278+
error => {
279+
caughtError = error;
280+
return resolve(onFinally());
281+
}
282+
)
283+
// In case onFinally throws we need to reject from this matcher
284+
.catch(error => {
285+
reject(error);
286+
});
282287
});
283288
}
284289
} catch (error) {

0 commit comments

Comments
 (0)