forked from enzymejs/enzyme
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull shallow renderer from react-test-renderer/shallow for React 15.5
- Loading branch information
Brian Vaughn
committed
Apr 8, 2017
1 parent
7c030cb
commit dbb029f
Showing
2 changed files
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
"react:clean": "rimraf node_modules/react node_modules/react-dom node_modules/react-addons-test-utils", | ||
"react:13": "rimraf node_modules/.bin/npm && npm run react:clean && npm i [email protected] && npm install", | ||
"react:14": "rimraf node_modules/.bin/npm && npm run react:clean && npm i [email protected] [email protected] [email protected] && npm install", | ||
"react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 prop-types@15 create-react-class@15 && npm install", | ||
"react:15": "rimraf node_modules/.bin/npm && npm run react:clean && npm i react@15 react-dom@15 react-addons-test-utils@15 prop-types@15 create-react-class@15 react-test-renderer@15 && npm install", | ||
"docs:clean": "rimraf _book", | ||
"docs:prepare": "gitbook install", | ||
"docs:build": "npm run docs:prepare && gitbook build", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ let unmountComponentAtNode; | |
let batchedUpdates; | ||
let PropTypes; | ||
let createClass; | ||
let shallowRendererFactory; | ||
|
||
const React = require('react'); | ||
|
||
|
@@ -114,6 +115,26 @@ if (REACT013) { | |
throw e; | ||
} | ||
|
||
// Shallow renderer is accessible via the react-test-renderer package for React 15.5+. | ||
// This is a separate package though and may not be installed. | ||
try { | ||
if (REACT155) { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
shallowRendererFactory = require('react-test-renderer/shallow').createRenderer; | ||
} else { | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
shallowRendererFactory = TestUtils.createRenderer; | ||
} | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error( | ||
'react-test-renderer is an implicit dependency in order to support [email protected]+. ' + | ||
'Please add the appropriate version to your devDependencies. ' + | ||
'See https://github.com/airbnb/enzyme#installation', | ||
); | ||
throw e; | ||
} | ||
|
||
// Shallow rendering changed from 0.13 => 0.14 in such a way that | ||
// 0.14 now does not allow shallow rendering of native DOM elements. | ||
// This is mainly because the result of such a call should not realistically | ||
|
@@ -122,7 +143,7 @@ if (REACT013) { | |
// is essentially a replacement for `TestUtils.createRenderer` that doesn't use | ||
// shallow rendering when it's just a DOM element. | ||
createShallowRenderer = function createRendererCompatible() { | ||
const renderer = TestUtils.createRenderer(); | ||
const renderer = shallowRendererFactory(); | ||
const originalRender = renderer.render; | ||
const originalRenderOutput = renderer.getRenderOutput; | ||
let isDOM = false; | ||
|