Commit c7817d2 1 parent a3d29dd commit c7817d2 Copy full SHA for c7817d2
File tree 2 files changed +7
-8
lines changed
2 files changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -373,7 +373,7 @@ describe('ReactDOM', () => {
373
373
}
374
374
} ) ;
375
375
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' , ( ) => {
377
377
spyOnDev ( console , 'error' ) ;
378
378
class App extends React . Component {
379
379
state = { x : 1 } ;
@@ -394,9 +394,7 @@ describe('ReactDOM', () => {
394
394
delete global . document ;
395
395
const fn = ( ) => instance . setState ( { x : 2 } ) ;
396
396
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 (
400
398
'The `document` global was defined when React was initialized, but is not ' +
401
399
'defined anymore. This can happen in a test environment if a component ' +
402
400
'schedules an update from an asynchronous callback, but the test has already ' +
Original file line number Diff line number Diff line change 8
8
*/
9
9
10
10
import invariant from 'fbjs/lib/invariant' ;
11
- import warning from 'fbjs/lib/warning' ;
12
11
13
12
const ReactErrorUtils = {
14
13
// Used by Fiber to simulate a try-catch.
@@ -168,9 +167,11 @@ if (__DEV__) {
168
167
e ,
169
168
f ,
170
169
) {
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 (
174
175
typeof document !== 'undefined' ,
175
176
'The `document` global was defined when React was initialized, but is not ' +
176
177
'defined anymore. This can happen in a test environment if a component ' +
You can’t perform that action at this time.
0 commit comments