@@ -319,43 +319,52 @@ describe('creating element with ref in constructor', () => {
319
319
'for the full message or use the non-minified dev environment for full errors and additional ' +
320
320
'helpful warnings.' ;
321
321
322
- it ( 'throws an error when __DEV__ = true' , ( ) => {
323
- ReactTestUtils = require ( 'ReactTestUtils' ) ;
322
+ describe ( 'when in development' , ( ) => {
323
+ it ( 'throws an error' , ( ) => {
324
+ ReactTestUtils = require ( 'ReactTestUtils' ) ;
324
325
325
- var originalDev = __DEV__ ;
326
- __DEV__ = true ;
327
-
328
- try {
329
326
expect ( function ( ) {
330
327
ReactTestUtils . renderIntoDocument ( < RefTest /> ) ;
331
328
} ) . toThrowError (
332
329
ReactDOMFeatureFlags . useFiber ? fiberDevErrorMessage : devErrorMessage ,
333
330
) ;
334
- } finally {
335
- __DEV__ = originalDev ;
336
- }
331
+ } ) ;
337
332
} ) ;
338
333
339
- it ( 'throws an error when __DEV__ = false ', ( ) => {
340
- ReactTestUtils = require ( 'ReactTestUtils' ) ;
334
+ describe ( ' when in production ', ( ) => {
335
+ var oldProcess ;
341
336
342
- var originalDev = __DEV__ ;
343
- var originalEnv = process . env . NODE_ENV ;
337
+ beforeEach ( ( ) => {
338
+ __DEV__ = false ;
344
339
345
- __DEV__ = false ;
346
- process . env . NODE_ENV = 'production' ;
340
+ // Mutating process.env.NODE_ENV would cause our babel plugins to do the
341
+ // wrong thing. If you change this, make sure to test with jest --no-cache.
342
+ oldProcess = process ;
343
+ global . process = {
344
+ ...process ,
345
+ env : { ...process . env , NODE_ENV : 'production' } ,
346
+ } ;
347
+
348
+ jest . resetModules ( ) ;
349
+ React = require ( 'React' ) ;
350
+ ReactTestUtils = require ( 'ReactTestUtils' ) ;
351
+ ReactDOMFeatureFlags = require ( 'ReactDOMFeatureFlags' ) ;
352
+ reactComponentExpect = require ( 'reactComponentExpect' ) ;
353
+ } ) ;
347
354
348
- try {
355
+ afterEach ( ( ) => {
356
+ __DEV__ = true ;
357
+ global . process = oldProcess ;
358
+ } ) ;
359
+
360
+ it ( 'throws an error' , ( ) => {
349
361
expect ( function ( ) {
350
362
ReactTestUtils . renderIntoDocument ( < RefTest /> ) ;
351
363
} ) . toThrowError (
352
364
ReactDOMFeatureFlags . useFiber
353
365
? fiberProdErrorMessage
354
366
: prodErrorMessage ,
355
367
) ;
356
- } finally {
357
- __DEV__ = originalDev ;
358
- process . env . NODE_ENV = originalEnv ;
359
- }
368
+ } ) ;
360
369
} ) ;
361
370
} ) ;
0 commit comments