Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support react-test-renderer #26

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ function componentWillMount() {
function componentWillReceiveProps(nextProps) {
// Call this.constructor.gDSFP to support sub-classes.
// Use the setState() updater to ensure state isn't stale in certain edge cases.
this.setState(function updater(prevState) {
function updater(prevState) {
var state = this.constructor.getDerivedStateFromProps(nextProps, prevState);
return state !== null && state !== undefined ? state : null;
});
}
this.setState(updater.bind(this));
}

function componentWillUpdate(nextProps, nextState) {
Expand Down
1 change: 1 addition & 0 deletions react/0.14.9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "0.14.9",
"react-addons-test-utils": "0.14.8",
"react-dom": "0.14.9"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions react/0.14.9/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ q@^1.1.2:
version "1.5.1"
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"

[email protected]:
version "0.14.8"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-0.14.8.tgz#dcddc039e71fc3c81d80338e53a3714f14d41e1f"

[email protected]:
version "0.14.9"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-0.14.9.tgz#05064a3dcf0fb1880a3b2bfc9d58c55d8d9f6293"
Expand Down
1 change: 1 addition & 0 deletions react/15.0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.0",
"react-addons-test-utils": "15.0",
"react-dom": "15.0"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions react/15.0/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

[email protected]:
version "15.0.2"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.0.2.tgz#43457b8b42ecc28690cb18d61bedd99db248cf93"

[email protected]:
version "15.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.0.2.tgz#f8a20ac1bc2da9eb494fce3b44c3ec19d0951e27"
Expand Down
1 change: 1 addition & 0 deletions react/15.1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.1",
"react-addons-test-utils": "15.1",
"react-dom": "15.1"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions react/15.1/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

[email protected]:
version "15.1.0"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.1.0.tgz#ed9ab2a99ecf04acc99eeea10b308105eb3b183c"

[email protected]:
version "15.1.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.1.0.tgz#d0c2b24c8b47a41a2b9ec766662d4e686f353153"
Expand Down
1 change: 1 addition & 0 deletions react/15.2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.2",
"react-addons-test-utils": "15.2",
"react-dom": "15.2"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions react/15.2/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

[email protected]:
version "15.2.1"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.2.1.tgz#38dfa2fe91d09603e5f27b2298665bc38a64bae1"

[email protected]:
version "15.2.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.2.1.tgz#dc942a5268f955e180158c9d4d2609fec9388ff0"
Expand Down
1 change: 1 addition & 0 deletions react/15.3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.3",
"react-addons-test-utils": "15.3",
"react-dom": "15.3"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions react/15.3/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

[email protected]:
version "15.3.2"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.3.2.tgz#c09a44f583425a4a9c1b38444d7a6c3e6f0f41f6"

[email protected]:
version "15.3.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.3.2.tgz#c46b0aa5380d7b838e7a59c4a7beff2ed315531f"
Expand Down
1 change: 1 addition & 0 deletions react/15.4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.4",
"react-addons-test-utils": "15.4",
"react-dom": "15.4"
},
"scripts": {
Expand Down
7 changes: 7 additions & 0 deletions react/15.4/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ promise@^7.1.1:
dependencies:
asap "~2.0.3"

[email protected]:
version "15.4.2"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.4.2.tgz#93bcaa718fcae7360d42e8fb1c09756cc36302a2"
dependencies:
fbjs "^0.8.4"
object-assign "^4.1.0"

[email protected]:
version "15.4.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-15.4.2.tgz#015363f05b0a1fd52ae9efdd3a0060d90695208f"
Expand Down
3 changes: 2 additions & 1 deletion react/15.5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.5",
"react-dom": "15.5"
"react-dom": "15.5",
"react-test-renderer": "15.5"
},
"scripts": {
"test": "jest test.js"
Expand Down
7 changes: 7 additions & 0 deletions react/15.5/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ [email protected]:
object-assign "^4.1.0"
prop-types "~15.5.7"

[email protected]:
version "15.5.4"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-15.5.4.tgz#d4ebb23f613d685ea8f5390109c2d20fbf7c83bc"
dependencies:
fbjs "^0.8.9"
object-assign "^4.1.0"

[email protected]:
version "15.5.4"
resolved "https://registry.yarnpkg.com/react/-/react-15.5.4.tgz#fa83eb01506ab237cdc1c8c3b1cea8de012bf047"
Expand Down
3 changes: 2 additions & 1 deletion react/15.6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "15.6",
"react-dom": "15.6"
"react-dom": "15.6",
"react-test-renderer": "15.6"
},
"scripts": {
"test": "jest test.js"
Expand Down
7 changes: 7 additions & 0 deletions react/15.6/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ [email protected]:
object-assign "^4.1.0"
prop-types "^15.5.10"

[email protected]:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-15.6.2.tgz#d0333434fc2c438092696ca770da5ed48037efa8"
dependencies:
fbjs "^0.8.9"
object-assign "^4.1.0"

[email protected]:
version "15.6.2"
resolved "https://registry.yarnpkg.com/react/-/react-15.6.2.tgz#dba0434ab439cfe82f108f0f511663908179aa72"
Expand Down
3 changes: 2 additions & 1 deletion react/16.0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "16.0",
"react-dom": "16.0"
"react-dom": "16.0",
"react-test-renderer": "16.0"
},
"scripts": {
"test": "jest test.js"
Expand Down
7 changes: 7 additions & 0 deletions react/16.0/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ [email protected]:
object-assign "^4.1.1"
prop-types "^15.6.0"

[email protected]:
version "16.0.0"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.0.0.tgz#9fe7b8308f2f71f29fc356d4102086f131c9cb15"
dependencies:
fbjs "^0.8.16"
object-assign "^4.1.1"

[email protected]:
version "16.0.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.0.0.tgz#ce7df8f1941b036f02b2cca9dbd0cb1f0e855e2d"
Expand Down
3 changes: 2 additions & 1 deletion react/16.1/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "16.1",
"react-dom": "16.1"
"react-dom": "16.1",
"react-test-renderer": "16.1"
},
"scripts": {
"test": "jest test.js"
Expand Down
8 changes: 8 additions & 0 deletions react/16.1/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ [email protected]:
object-assign "^4.1.1"
prop-types "^15.6.0"

[email protected]:
version "16.1.1"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.1.1.tgz#a05184688d564be799f212449262525d1e350537"
dependencies:
fbjs "^0.8.16"
object-assign "^4.1.1"
prop-types "^15.6.0"

[email protected]:
version "16.1.1"
resolved "https://registry.yarnpkg.com/react/-/react-16.1.1.tgz#d5c4ef795507e3012282dd51261ff9c0e824fe1f"
Expand Down
3 changes: 2 additions & 1 deletion react/16.2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "16.2",
"react-dom": "16.2"
"react-dom": "16.2",
"react-test-renderer": "16.2"
},
"scripts": {
"test": "jest test.js"
Expand Down
8 changes: 8 additions & 0 deletions react/16.2/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ [email protected]:
object-assign "^4.1.1"
prop-types "^15.6.0"

[email protected]:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.2.0.tgz#bddf259a6b8fcd8555f012afc8eacc238872a211"
dependencies:
fbjs "^0.8.16"
object-assign "^4.1.1"
prop-types "^15.6.0"

[email protected]:
version "16.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.2.0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba"
Expand Down
3 changes: 2 additions & 1 deletion react/16.3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"devDependencies": {
"create-react-class": "^15.6.2",
"react": "16.3",
"react-dom": "16.3"
"react-dom": "16.3",
"react-test-renderer": "16.3"
},
"scripts": {
"test": "jest test.js"
Expand Down
13 changes: 13 additions & 0 deletions react/16.3/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ [email protected]:
object-assign "^4.1.1"
prop-types "^15.6.0"

react-is@^16.3.2:
version "16.3.2"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.3.2.tgz#f4d3d0e2f5fbb6ac46450641eb2e25bf05d36b22"

[email protected]:
version "16.3.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.3.2.tgz#3d1ed74fda8db42521fdf03328e933312214749a"
dependencies:
fbjs "^0.8.16"
object-assign "^4.1.1"
prop-types "^15.6.0"
react-is "^16.3.2"

[email protected]:
version "16.3.0"
resolved "https://registry.yarnpkg.com/react/-/react-16.3.0.tgz#fc5a01c68f91e9b38e92cf83f7b795ebdca8ddff"
Expand Down
42 changes: 42 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ Object.entries(POLYFILLS).forEach(([name, module]) => {
let polyfill;
let React;
let ReactDOM;
let testRenderer;

beforeAll(() => {
createReactClass = require(basePath + 'create-react-class');
polyfill = module.polyfill;
React = require(basePath + 'react');
ReactDOM = require(basePath + 'react-dom');

let ReactTestRenderer;
try {
ReactTestRenderer = require(basePath + 'react-test-renderer/shallow');
} catch(e) {
ReactTestRenderer = require(basePath + 'react-addons-test-utils');
}
testRenderer = ReactTestRenderer.createRenderer();
});

describe(`react@${version}`, () => {
Expand Down Expand Up @@ -70,6 +79,39 @@ Object.entries(POLYFILLS).forEach(([name, module]) => {
expect(container.textContent).toBe('6');
});

it('should support shallow rendering', () => {
class ClassComponent extends React.Component {
constructor(props) {
super(props);
this.state = {count: 1};
}
static getDerivedStateFromProps(nextProps, prevState) {
return {
count: prevState.count + nextProps.incrementBy,
};
}
render() {
return React.createElement('div', null, this.state.count);
}
}

polyfill(ClassComponent);

testRenderer.render(
React.createElement(ClassComponent, {incrementBy: 2})
);

let result = testRenderer.getRenderOutput();
expect(result.props.children).toBe(3);

testRenderer.render(
React.createElement(ClassComponent, {incrementBy: 3})
);

result = testRenderer.getRenderOutput();
expect(result.props.children).toBe(6);
});

it('should support create-react-class components', () => {
let componentDidUpdateCalled = false;

Expand Down