Rejct toWarnDev if given callback throws (#26003)
## Summary Should unblock https://github.com/facebook/react/pull/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 https://github.com/facebook/react/pull/25970 with `yarn test --r=stable --env=development packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js --watch` - [x] `yarn test` - [x] CI
Sebastian Silbermann committed
Jan 15, 2023 at 18:57 UTC
4f8ffec453c41fcb6e98cb4e003f7319bb1c81b9
1 file changed
+14
-9
scripts/jest/matchers/toWarnDev.js
+14
-9
@@ -270,15 +270,20 @@ const createMatcherFor = (consoleMethod, matcherName) =>
270
// Once `act(async () => {}).then(() => {}).then(() => {})` works
271
// we can just return `result.then(onFinally, error => ...)`
272
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
+ });
287
});
288
}
289
} catch (error) {