-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Description
As reported in #4761 (comment), I tried 21.3.0-beta.3 on React codebase, and tests like
test('wat', () => {
const container = document.createElement('div');
function App() {
throw new Error('hi');
}
expect(() => {
ReactDOM.render(<App />, container);
}).toThrow();
});now fail. (The error blows up the test despite bring caught.)
However, they pass with 21.2.1.
To repro, you can take the test above, put it into ReactDOMComponent-test on React master, update Jest packages to 21.3.0-beta.3 and run yarn test ReactDOMComponent-test.
I haven't had time to verify if it's isolated to React Jest setup or not. But if it affects us, could affect someone else (or everyone) too.
The only unusual thing we do in React wrt error handling is that we wrap our code into a browser event so that browsers report unhandled (but caught and rethrown by us) errors as unhandled. This used to work with Jest too. You can disable this logic by changing __DEV__ to false here and then you'll see it goes back to normal (test passes).
So something related to how errors are handled in jsdom browser event loop has changed, and will likely break any tests relying on throwing (and intentionally catching) errors with React 16. Maybe jsdom was updated or something like this?
Note that if this got broken, it will affect anyone using React, not just us.
Here is the diff of lockfile: https://gist.github.com/gaearon/fc30d89381e6b4c6a2494b66f04455cf. Something here causes the issue.