Skip to content

Add test for pure-render logic #108

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

Merged
merged 2 commits into from
Mar 15, 2016
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"jsdom": "^8.0.4",
"pragmatist": "^3.0.16",
"react": "^0.15.0-alpha.1",
"react-addons-shallow-compare": "^0.15.0-alpha.1",
"react-addons-test-utils": "^0.15.0-alpha.1",
"react-dom": "^0.15.0-alpha.1"
},
Expand Down
31 changes: 31 additions & 0 deletions tests/extendReactClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {

import React from 'react';
import TestUtils from 'react-addons-test-utils';
import shallowCompare from 'react-addons-shallow-compare';
import jsdom from 'jsdom';
import extendReactClass from './../src/extendReactClass';

Expand Down Expand Up @@ -52,6 +53,36 @@ describe('extendReactClass', () => {

TestUtils.renderIntoDocument(<Component bar='baz' />);
});
it('does not affect pure-render logic', (done) => {
let Component,
instance,
rendered = false;

const styles = {
foo: 'foo-1'
};

Component = class extends React.Component {
shouldComponentUpdate(newProps) {
if(rendered) {
expect(shallowCompare(this.props, newProps)).to.be.true;
done();
}
return true;
}

render () {
rendered = true;
}
};

Component = extendReactClass(Component, styles);

instance = TestUtils.renderIntoDocument(<Component foo='bar'/>);

// trigger shouldComponentUpdate
instance.setState({});
});
});
context('overwriting default styles using "styles" property of the extended component', () => {
it('overwrites default styles', (done) => {
Expand Down