Skip to content

Commit

Permalink
Use invariant() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Nov 29, 2017
1 parent a3d29dd commit fc5c4f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
4 changes: 1 addition & 3 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ describe('ReactDOM', () => {
delete global.document;
const fn = () => instance.setState({x: 2});
if (__DEV__) {
expect(fn).toThrow('document is not defined');
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
expect(fn).toThrow(
'The `document` global was defined when React was initialized, but is not ' +
'defined anymore. This can happen in a test environment if a component ' +
'schedules an update from an asynchronous callback, but the test has already ' +
Expand Down
9 changes: 5 additions & 4 deletions packages/shared/ReactErrorUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
*/

import invariant from 'fbjs/lib/invariant';
import warning from 'fbjs/lib/warning';

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

0 comments on commit fc5c4f9

Please sign in to comment.