diff --git a/packages/react-dom/package.json b/packages/react-dom/package.json
index 52070cd964734..d1863e6507af0 100644
--- a/packages/react-dom/package.json
+++ b/packages/react-dom/package.json
@@ -27,6 +27,7 @@
"README.md",
"index.js",
"server.js",
+ "test-utils.js",
"cjs/",
"umd/"
],
diff --git a/packages/react-dom/test-utils.js b/packages/react-dom/test-utils.js
new file mode 100644
index 0000000000000..31e2a261949ca
--- /dev/null
+++ b/packages/react-dom/test-utils.js
@@ -0,0 +1,7 @@
+'use strict';
+
+if (process.env.NODE_ENV === 'production') {
+ throw Error('test-utils is not available in production mode.');
+} else {
+ module.exports = require('./cjs/react-dom-test-utils.development');
+}
diff --git a/packages/react-test-renderer/index.js b/packages/react-test-renderer/index.js
index 3a0cbe1a0417c..48895ee7cc19c 100644
--- a/packages/react-test-renderer/index.js
+++ b/packages/react-test-renderer/index.js
@@ -1,3 +1,7 @@
'use strict';
-module.exports = require('./cjs/react-test-renderer.development');
+if (process.env.NODE_ENV === 'production') {
+ throw Error('test renderer is not available in production mode.');
+} else {
+ module.exports = require('./cjs/react-test-renderer.development');
+}
diff --git a/packages/react-test-renderer/package.json b/packages/react-test-renderer/package.json
index a9cedf4ce70d9..86d25aff481d6 100644
--- a/packages/react-test-renderer/package.json
+++ b/packages/react-test-renderer/package.json
@@ -26,6 +26,7 @@
"PATENTS",
"README.md",
"index.js",
+ "shallow.js",
"cjs/"
]
}
diff --git a/packages/react-test-renderer/shallow.js b/packages/react-test-renderer/shallow.js
new file mode 100644
index 0000000000000..b75c643cf0eca
--- /dev/null
+++ b/packages/react-test-renderer/shallow.js
@@ -0,0 +1,7 @@
+'use strict';
+
+if (process.env.NODE_ENV === 'production') {
+ throw Error('shallow renderer is not available in production mode.');
+} else {
+ module.exports = require('./cjs/react-test-renderer-shallow.development');
+}
diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt
index 0cf8d024093b5..ab1c2f7577866 100644
--- a/scripts/fiber/tests-passing.txt
+++ b/scripts/fiber/tests-passing.txt
@@ -1560,6 +1560,41 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMTextarea-test.js
* should warn if value is null
* should warn if value and defaultValue are specified
+src/renderers/dom/test/__tests__/ReactTestUtils-test.js
+* should call all of the lifecycle hooks
+* should only render 1 level deep
+* should have shallow rendering
+* should enable shouldComponentUpdate to prevent a re-render
+* should shallow render a functional component
+* should throw for invalid elements
+* should have shallow unmounting
+* can shallow render to null
+* can shallow render with a ref
+* lets you update shallowly rendered components
+* can access the mounted component instance
+* can shallowly render components with contextTypes
+* can shallowly render components with ref as function
+* can setState in componentWillMount when shallow rendering
+* can setState in componentWillReceiveProps when shallow rendering
+* can setState with an updater function
+* can pass context when shallowly rendering
+* should track context across updates
+* can fail context when shallowly rendering
+* should warn about propTypes (but only once)
+* can scryRenderedDOMComponentsWithClass with TextComponent
+* can scryRenderedDOMComponentsWithClass with className contains \n
+* can scryRenderedDOMComponentsWithClass with multiple classes
+* traverses children in the correct order
+* should support injected wrapper components as DOM components
+* should change the value of an input field
+* should change the value of an input field in a component
+* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
+* should not warn when simulating events with extra properties
+* can scry with stateless components involved
+* should enable rendering of cloned element
+* should set the type of the event
+* should work with renderIntoDocument
+
src/renderers/native/__tests__/ReactNativeAttributePayload-test.js
* should work with simple example
* should skip fields that are equal
@@ -1868,32 +1903,6 @@ src/shared/utils/__tests__/PooledClass-test.js
src/shared/utils/__tests__/reactProdInvariant-test.js
* should throw with the correct number of `%s`s in the URL
-src/test/__tests__/ReactTestUtils-test.js
-* should have shallow rendering
-* should shallow render a functional component
-* should throw for invalid elements
-* should have shallow unmounting
-* can shallow render to null
-* can shallow render with a ref
-* lets you update shallowly rendered components
-* can access the mounted component instance
-* can shallowly render components with contextTypes
-* can shallowly render components with ref as function
-* can setState in componentWillMount when shallow rendering
-* can pass context when shallowly rendering
-* can fail context when shallowly rendering
-* can scryRenderedDOMComponentsWithClass with TextComponent
-* can scryRenderedDOMComponentsWithClass with className contains \n
-* can scryRenderedDOMComponentsWithClass with multiple classes
-* traverses children in the correct order
-* should support injected wrapper components as DOM components
-* should change the value of an input field
-* should change the value of an input field in a component
-* should throw when attempting to use ReactTestUtils.Simulate with shallow rendering
-* should not warn when simulating events with extra properties
-* can scry with stateless components involved
-* should set the type of the event
-
src/test/__tests__/reactComponentExpect-test.js
* should match composite components
* should match empty DOM components
diff --git a/scripts/rollup/bundles.js b/scripts/rollup/bundles.js
index cc33df8d123e8..7d90027c59339 100644
--- a/scripts/rollup/bundles.js
+++ b/scripts/rollup/bundles.js
@@ -89,9 +89,7 @@ const bundles = [
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
- 'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
@@ -118,9 +116,41 @@ const bundles = [
paths: [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
- 'src/test/**/*.js', // ReactTestUtils is currently very coupled to DOM.
- 'src/isomorphic/classic/types/checkPropTypes.js',
+ 'src/ReactVersion.js',
+ 'src/shared/**/*.js',
+ ],
+ },
+ {
+ babelOpts: babelOptsReact,
+ bundleTypes: [FB_DEV, NODE_DEV],
+ config: {
+ destDir: 'build/',
+ globals: {
+ react: 'React',
+ },
+ moduleName: 'ReactTestUtils',
+ sourceMap: false,
+ },
+ entry: 'src/renderers/dom/test/ReactTestUtils',
+ externals: [
+ 'prop-types',
+ 'prop-types/checkPropTypes',
+ 'react',
+ 'react-dom',
+ 'react-test-renderer', // TODO (bvaughn) Remove this dependency before 16.0.0
+ ],
+ fbEntry: 'src/renderers/dom/test/ReactTestUtils',
+ hasteName: 'ReactTestUtils',
+ isRenderer: true,
+ label: 'test-utils',
+ manglePropertiesOnProd: false,
+ name: 'react-dom/test-utils',
+ paths: [
+ 'src/renderers/dom/test/**/*.js',
+ 'src/renderers/shared/**/*.js',
+ 'src/renderers/testing/**/*.js', // TODO (bvaughn) Remove this dependency before 16.0.0
+
'src/ReactVersion.js',
'src/shared/**/*.js',
],
@@ -151,7 +181,6 @@ const bundles = [
'src/renderers/dom/**/*.js',
'src/renderers/shared/**/*.js',
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
@@ -190,7 +219,6 @@ const bundles = [
'src/renderers/art/**/*.js',
'src/renderers/shared/**/*.js',
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
@@ -226,7 +254,6 @@ const bundles = [
'src/renderers/art/**/*.js',
'src/renderers/shared/**/*.js',
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
@@ -328,12 +355,10 @@ const bundles = [
'src/renderers/shared/**/*.js',
'src/renderers/testing/**/*.js',
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
},
-
{
babelOpts: babelOptsReact,
bundleTypes: [FB_DEV],
@@ -355,11 +380,32 @@ const bundles = [
'src/renderers/shared/**/*.js',
'src/renderers/testing/**/*.js',
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
},
+ {
+ babelOpts: babelOptsReact,
+ bundleTypes: [FB_DEV, NODE_DEV],
+ config: {
+ destDir: 'build/',
+ moduleName: 'ReactShallowRenderer',
+ sourceMap: false,
+ },
+ entry: 'src/renderers/testing/ReactShallowRenderer',
+ externals: [
+ 'react-dom',
+ 'prop-types/checkPropTypes',
+ 'react-test-renderer',
+ ],
+ fbEntry: 'src/renderers/testing/ReactShallowRenderer',
+ hasteName: 'ReactShallowRenderer',
+ isRenderer: true,
+ label: 'shallow-renderer',
+ manglePropertiesOnProd: false,
+ name: 'react-test-renderer/shallow',
+ paths: ['src/renderers/shared/**/*.js', 'src/renderers/testing/**/*.js'],
+ },
/******* React Noop Renderer (used only for fixtures/fiber-debugger) *******/
{
@@ -383,7 +429,6 @@ const bundles = [
'src/renderers/noop/**/*.js',
'src/renderers/shared/**/*.js',
- 'src/isomorphic/classic/types/checkPropTypes.js',
'src/ReactVersion.js',
'src/shared/**/*.js',
],
diff --git a/scripts/rollup/shims/facebook-www/ReactTestUtils.js b/scripts/rollup/shims/facebook-www/ReactTestUtils.js
deleted file mode 100644
index dafb421d1d187..0000000000000
--- a/scripts/rollup/shims/facebook-www/ReactTestUtils.js
+++ /dev/null
@@ -1,18 +0,0 @@
-/**
- * Copyright 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule ReactTestUtils
- */
-
-'use strict';
-
-const {
- __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
-} = require('ReactDOM-fb');
-
-module.exports = __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactTestUtils;
diff --git a/src/fb/ReactDOMFBEntry.js b/src/fb/ReactDOMFBEntry.js
index 754febaf3637a..c4e8c003fc8cf 100644
--- a/src/fb/ReactDOMFBEntry.js
+++ b/src/fb/ReactDOMFBEntry.js
@@ -43,10 +43,9 @@ Object.assign(ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
if (__DEV__) {
Object.assign(ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
- // ReactPerf and ReactTestUtils currently only work with the DOM renderer
- // so we expose them from here, but only in DEV mode.
+ // ReactPerf currently only works with the DOM renderer
+ // so we expose it here, but only in DEV mode.
ReactPerf: require('ReactPerf'),
- ReactTestUtils: require('ReactTestUtils'),
});
}
diff --git a/src/fb/ReactDOMFiberFBEntry.js b/src/fb/ReactDOMFiberFBEntry.js
index 188b9c71248ca..9ecaa6fe07844 100644
--- a/src/fb/ReactDOMFiberFBEntry.js
+++ b/src/fb/ReactDOMFiberFBEntry.js
@@ -45,15 +45,4 @@ Object.assign(
},
);
-if (__DEV__) {
- Object.assign(
- ReactDOMFiber.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
- {
- // ReactPerf and ReactTestUtils currently only work with the DOM renderer
- // so we expose them from here, but only in DEV mode.
- ReactTestUtils: require('ReactTestUtils'),
- },
- );
-}
-
module.exports = ReactDOMFiber;
diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js
index 807a1c369f4f5..eebe7b9b556a9 100644
--- a/src/isomorphic/React.js
+++ b/src/isomorphic/React.js
@@ -19,7 +19,7 @@ var ReactPropTypes = require('ReactPropTypes');
var ReactVersion = require('ReactVersion');
var onlyChild = require('onlyChild');
-var checkPropTypes = require('checkPropTypes');
+var checkPropTypes = require('prop-types/checkPropTypes');
var createReactClass = require('createClass');
var createElement = ReactElement.createElement;
@@ -57,7 +57,7 @@ var React = {
cloneElement: cloneElement,
isValidElement: ReactElement.isValidElement,
- // TODO (bvaughn) Remove these getters in 16.0.0-alpha.10
+ // TODO (bvaughn) Remove these getters before 16.0.0
PropTypes: ReactPropTypes,
checkPropTypes: checkPropTypes,
createClass: createReactClass,
@@ -100,7 +100,7 @@ if (__DEV__) {
return mixin;
};
- // TODO (bvaughn) Remove both of these deprecation warnings in 16.0.0-alpha.10
+ // TODO (bvaughn) Remove both of these deprecation warnings before 16.0.0
if (canDefineProperty) {
Object.defineProperty(React, 'checkPropTypes', {
get() {
diff --git a/src/isomorphic/classic/element/ReactElementValidator.js b/src/isomorphic/classic/element/ReactElementValidator.js
index 9840ba3a59bb8..cf2682168b6e0 100644
--- a/src/isomorphic/classic/element/ReactElementValidator.js
+++ b/src/isomorphic/classic/element/ReactElementValidator.js
@@ -26,7 +26,7 @@ var getComponentName = require('getComponentName');
var getIteratorFn = require('getIteratorFn');
if (__DEV__) {
- var checkPropTypes = require('checkPropTypes');
+ var checkPropTypes = require('prop-types/checkPropTypes');
var warning = require('fbjs/lib/warning');
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
var {
diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
index edcaca7a6f9a0..ce4c2e183372e 100644
--- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
@@ -21,7 +21,7 @@ var MyComponent;
function resetWarningCache() {
jest.resetModules();
- checkPropTypes = require('checkPropTypes');
+ checkPropTypes = require('prop-types/checkPropTypes');
}
function getPropTypeWarningMessage(propTypes, object, componentName) {
diff --git a/src/isomorphic/classic/types/checkPropTypes.js b/src/isomorphic/classic/types/checkPropTypes.js
deleted file mode 100644
index 32d9ecc677497..0000000000000
--- a/src/isomorphic/classic/types/checkPropTypes.js
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * Copyright 2013-present, Facebook, Inc.
- * All rights reserved.
- *
- * This source code is licensed under the BSD-style license found in the
- * LICENSE file in the root directory of this source tree. An additional grant
- * of patent rights can be found in the PATENTS file in the same directory.
- *
- * @providesModule checkPropTypes
- */
-
-'use strict';
-
-module.exports = require('prop-types/checkPropTypes');
diff --git a/src/node_modules/react/lib/checkPropTypes.js b/src/node_modules/react-test-renderer/index.js
similarity index 66%
rename from src/node_modules/react/lib/checkPropTypes.js
rename to src/node_modules/react-test-renderer/index.js
index 083e4df83ad8a..a11b1836c7b0d 100644
--- a/src/node_modules/react/lib/checkPropTypes.js
+++ b/src/node_modules/react-test-renderer/index.js
@@ -6,4 +6,4 @@
'use strict';
-module.exports = require('checkPropTypes');
+module.exports = require('ReactTestRenderer');
diff --git a/src/renderers/dom/ReactDOM.js b/src/renderers/dom/ReactDOM.js
index f5f976ea7d4aa..601ce0d924b33 100644
--- a/src/renderers/dom/ReactDOM.js
+++ b/src/renderers/dom/ReactDOM.js
@@ -42,6 +42,12 @@ var ReactDOM = {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
// For TapEventPlugin which is popular in open source
EventPluginHub: require('EventPluginHub'),
+ // Used by test-utils
+ EventPluginRegistry: require('EventPluginRegistry'),
+ EventPropagators: require('EventPropagators'),
+ ReactControlledComponent: require('ReactControlledComponent'),
+ ReactDOMComponentTree,
+ ReactBrowserEventEmitter: require('ReactBrowserEventEmitter'),
},
};
diff --git a/src/renderers/dom/fiber/ReactDOMFiber.js b/src/renderers/dom/fiber/ReactDOMFiber.js
index bb327bb36b441..d3ed8381ca2d4 100644
--- a/src/renderers/dom/fiber/ReactDOMFiber.js
+++ b/src/renderers/dom/fiber/ReactDOMFiber.js
@@ -542,6 +542,12 @@ var ReactDOM = {
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
// For TapEventPlugin which is popular in open source
EventPluginHub: require('EventPluginHub'),
+ // Used by test-utils
+ EventPluginRegistry: require('EventPluginRegistry'),
+ EventPropagators: require('EventPropagators'),
+ ReactControlledComponent,
+ ReactDOMComponentTree,
+ ReactBrowserEventEmitter,
},
};
diff --git a/src/test/ReactTestUtils.js b/src/renderers/dom/test/ReactTestUtils.js
similarity index 93%
rename from src/test/ReactTestUtils.js
rename to src/renderers/dom/test/ReactTestUtils.js
index f320be4bd12b5..23ac6fd774f9b 100644
--- a/src/test/ReactTestUtils.js
+++ b/src/renderers/dom/test/ReactTestUtils.js
@@ -12,23 +12,26 @@
'use strict';
var EventConstants = require('EventConstants');
-var EventPluginHub = require('EventPluginHub');
-var EventPluginRegistry = require('EventPluginRegistry');
-var EventPropagators = require('EventPropagators');
var React = require('react');
-var ReactControlledComponent = require('ReactControlledComponent');
-var ReactDOM = require('ReactDOM');
-var ReactDOMComponentTree = require('ReactDOMComponentTree');
-var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
+var ReactDOM = require('react-dom');
var ReactFiberTreeReflection = require('ReactFiberTreeReflection');
var ReactInstanceMap = require('ReactInstanceMap');
+var ReactShallowRenderer = require('ReactShallowRenderer'); // TODO (bvaughn) Remove this import before 16.0.0
var ReactTypeOfWork = require('ReactTypeOfWork');
-var ReactGenericBatching = require('ReactGenericBatching');
var SyntheticEvent = require('SyntheticEvent');
-var ReactShallowRenderer = require('ReactShallowRenderer');
-var findDOMNode = require('findDOMNode');
var invariant = require('fbjs/lib/invariant');
+var warning = require('fbjs/lib/warning');
+
+var {findDOMNode} = ReactDOM;
+var {
+ EventPluginHub,
+ EventPluginRegistry,
+ EventPropagators,
+ ReactBrowserEventEmitter,
+ ReactControlledComponent,
+ ReactDOMComponentTree,
+} = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
var topLevelTypes = EventConstants.topLevelTypes;
var {
@@ -38,6 +41,20 @@ var {
HostText,
} = ReactTypeOfWork;
+// TODO (bvaughn) Remove this warning before 16.0.0
+// It's only being added for temporary deprecation notice in RN.
+let warnedAboutShallowRenderer = false;
+function createRendererWithWarning() {
+ warning(
+ warnedAboutShallowRenderer,
+ 'Shallow renderer has been moved to react-test-renderer/shallow. ' +
+ 'Update references to remove this warning. ' +
+ 'TestUtils.createRenderer will be removed completely in React 16.',
+ );
+ warnedAboutShallowRenderer = true;
+ return new ReactShallowRenderer();
+}
+
function Event(suffix) {}
/**
@@ -403,9 +420,9 @@ var ReactTestUtils = {
};
},
- createRenderer: function() {
- return new ReactShallowRenderer();
- },
+ // TODO (bvaughn) Remove this warning accessor before 16.0.0.
+ // It's only being added for temporary deprecation notice in RN.
+ createRenderer: createRendererWithWarning,
Simulate: null,
SimulateNative: {},
@@ -462,7 +479,7 @@ function makeSimulator(eventType) {
EventPropagators.accumulateDirectDispatches(event);
}
- ReactGenericBatching.batchedUpdates(function() {
+ ReactDOM.unstable_batchedUpdates(function() {
// Normally extractEvent enqueues a state restore, but we'll just always
// do that since we we're by-passing it here.
ReactControlledComponent.enqueueStateRestore(node);
diff --git a/src/test/__tests__/ReactTestUtils-test.js b/src/renderers/dom/test/__tests__/ReactTestUtils-test.js
similarity index 55%
rename from src/test/__tests__/ReactTestUtils-test.js
rename to src/renderers/dom/test/__tests__/ReactTestUtils-test.js
index cd1b2a5dc8a5c..2623e0fa89393 100644
--- a/src/test/__tests__/ReactTestUtils-test.js
+++ b/src/renderers/dom/test/__tests__/ReactTestUtils-test.js
@@ -11,14 +11,16 @@
'use strict';
-var PropTypes;
-var React;
-var ReactDOM;
-var ReactDOMServer;
-var ReactTestUtils;
+let createRenderer;
+let PropTypes;
+let React;
+let ReactDOM;
+let ReactDOMServer;
+let ReactTestUtils;
describe('ReactTestUtils', () => {
beforeEach(() => {
+ createRenderer = require('ReactShallowRenderer').createRenderer;
PropTypes = require('prop-types');
React = require('react');
ReactDOM = require('react-dom');
@@ -26,6 +28,66 @@ describe('ReactTestUtils', () => {
ReactTestUtils = require('ReactTestUtils');
});
+ it('should call all of the lifecycle hooks', () => {
+ const logs = [];
+ const logger = message => () => logs.push(message) || true;
+
+ class SomeComponent extends React.Component {
+ componentWillMount = logger('componentWillMount');
+ componentDidMount = logger('componentDidMount');
+ componentWillReceiveProps = logger('componentWillReceiveProps');
+ shouldComponentUpdate = logger('shouldComponentUpdate');
+ componentWillUpdate = logger('componentWillUpdate');
+ componentDidUpdate = logger('componentDidUpdate');
+ componentWillUnmount = logger('componentWillUnmount');
+ render() {
+ return
;
+ }
+ }
+
+ const shallowRenderer = createRenderer();
+ shallowRenderer.render();
+
+ // Calling cDU might lead to problems with host component references.
+ // Since our components aren't really mounted, refs won't be available.
+ expect(logs).toEqual(['componentWillMount']);
+
+ logs.splice(0);
+
+ const instance = shallowRenderer.getMountedInstance();
+ instance.setState({});
+
+ // The previous shallow renderer triggered cDU for setState() calls.
+ expect(logs).toEqual([
+ 'shouldComponentUpdate',
+ 'componentWillUpdate',
+ 'componentDidUpdate',
+ ]);
+
+ logs.splice(0);
+
+ shallowRenderer.render();
+
+ // The previous shallow renderer did not trigger cDU for props changes.
+ expect(logs).toEqual([
+ 'componentWillReceiveProps',
+ 'shouldComponentUpdate',
+ 'componentWillUpdate',
+ ]);
+ });
+
+ it('should only render 1 level deep', () => {
+ function Parent() {
+ return
;
+ }
+ function Child() {
+ throw Error('This component should not render');
+ }
+
+ const shallowRenderer = createRenderer();
+ shallowRenderer.render(React.createElement(Parent));
+ });
+
it('should have shallow rendering', () => {
class SomeComponent extends React.Component {
render() {
@@ -38,8 +100,8 @@ describe('ReactTestUtils', () => {
}
}
- var shallowRenderer = ReactTestUtils.createRenderer();
- var result = shallowRenderer.render();
+ const shallowRenderer = createRenderer();
+ const result = shallowRenderer.render();
expect(result.type).toBe('div');
expect(result.props.children).toEqual([
@@ -48,21 +110,52 @@ describe('ReactTestUtils', () => {
]);
});
+ it('should enable shouldComponentUpdate to prevent a re-render', () => {
+ let renderCounter = 0;
+ class SimpleComponent extends React.Component {
+ state = {update: false};
+ shouldComponentUpdate(nextProps, nextState) {
+ return this.state.update !== nextState.update;
+ }
+ render() {
+ renderCounter++;
+ return