Skip to content

Commit

Permalink
Use standard method of testing for production
Browse files Browse the repository at this point in the history
  • Loading branch information
nhunzaker committed Sep 6, 2017
1 parent da62f42 commit 26722ce
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions src/renderers/shared/stack/reconciler/__tests__/refs-test.js
Expand Up @@ -319,43 +319,52 @@ describe('creating element with ref in constructor', () => {
'for the full message or use the non-minified dev environment for full errors and additional ' +
'helpful warnings.';

it('throws an error when __DEV__ = true', () => {
ReactTestUtils = require('ReactTestUtils');
describe('when in development', () => {
it('throws an error', () => {
ReactTestUtils = require('ReactTestUtils');

var originalDev = __DEV__;
__DEV__ = true;

try {
expect(function() {
ReactTestUtils.renderIntoDocument(<RefTest />);
}).toThrowError(
ReactDOMFeatureFlags.useFiber ? fiberDevErrorMessage : devErrorMessage,
);
} finally {
__DEV__ = originalDev;
}
});
});

it('throws an error when __DEV__ = false', () => {
ReactTestUtils = require('ReactTestUtils');
describe('when in production', () => {
var oldProcess;

var originalDev = __DEV__;
var originalEnv = process.env.NODE_ENV;
beforeEach(() => {
__DEV__ = false;

__DEV__ = false;
process.env.NODE_ENV = 'production';
// Mutating process.env.NODE_ENV would cause our babel plugins to do the
// wrong thing. If you change this, make sure to test with jest --no-cache.
oldProcess = process;
global.process = {
...process,
env: {...process.env, NODE_ENV: 'production'},
};

jest.resetModules();
React = require('React');
ReactTestUtils = require('ReactTestUtils');
ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
reactComponentExpect = require('reactComponentExpect');
});

try {
afterEach(() => {
__DEV__ = true;
global.process = oldProcess;
});

it('throws an error', () => {
expect(function() {
ReactTestUtils.renderIntoDocument(<RefTest />);
}).toThrowError(
ReactDOMFeatureFlags.useFiber
? fiberProdErrorMessage
: prodErrorMessage,
);
} finally {
__DEV__ = originalDev;
process.env.NODE_ENV = originalEnv;
}
});
});
});

0 comments on commit 26722ce

Please sign in to comment.