Skip to content

Commit c7817d2

Browse files
committed
Use invariant() instead
1 parent a3d29dd commit c7817d2

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

packages/react-dom/src/__tests__/ReactDOM-test.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ describe('ReactDOM', () => {
373373
}
374374
});
375375

376-
it('warns in DEV if jsdom is destroyed by the time setState() is called', () => {
376+
it('throws in DEV if jsdom is destroyed by the time setState() is called', () => {
377377
spyOnDev(console, 'error');
378378
class App extends React.Component {
379379
state = {x: 1};
@@ -394,9 +394,7 @@ describe('ReactDOM', () => {
394394
delete global.document;
395395
const fn = () => instance.setState({x: 2});
396396
if (__DEV__) {
397-
expect(fn).toThrow('document is not defined');
398-
expect(console.error.calls.count()).toBe(1);
399-
expect(console.error.calls.argsFor(0)[0]).toContain(
397+
expect(fn).toThrow(
400398
'The `document` global was defined when React was initialized, but is not ' +
401399
'defined anymore. This can happen in a test environment if a component ' +
402400
'schedules an update from an asynchronous callback, but the test has already ' +

packages/shared/ReactErrorUtils.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
import invariant from 'fbjs/lib/invariant';
11-
import warning from 'fbjs/lib/warning';
1211

1312
const ReactErrorUtils = {
1413
// Used by Fiber to simulate a try-catch.
@@ -168,9 +167,11 @@ if (__DEV__) {
168167
e,
169168
f,
170169
) {
171-
// If document doesn't exist we know for sure we will crash in this method later.
172-
// So we show a warning explaining a potential cause.
173-
warning(
170+
// If document doesn't exist we know for sure we will crash in this method
171+
// when we call document.createEvent(). However this can cause confusing
172+
// errors: https://github.com/facebookincubator/create-react-app/issues/3482
173+
// So we preemptively throw with a better message instead.
174+
invariant(
174175
typeof document !== 'undefined',
175176
'The `document` global was defined when React was initialized, but is not ' +
176177
'defined anymore. This can happen in a test environment if a component ' +

0 commit comments

Comments
 (0)