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

Normalized setProps behavior between mount/shallow #103

Merged
merged 1 commit into from
Jan 7, 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 @@ -47,6 +47,7 @@
"license": "MIT",
"dependencies": {
"cheerio": "^0.19.0",
"object.assign": "^4.0.3",
"sinon": "^1.15.4",
"underscore": "^1.8.3"
},
Expand Down
4 changes: 3 additions & 1 deletion src/ReactWrapperComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react';
import objectAssign from 'object.assign';

/**
* This is a utility component to wrap around the nodes we are
Expand Down Expand Up @@ -30,7 +31,8 @@ export default function createWrapperComponent(node, options = {}) {
};
},

setChildProps(props) {
setChildProps(newProps) {
const props = objectAssign({}, this.state.props, newProps);
return new Promise(resolve => this.setState({ props }, resolve));
},

Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,25 @@ describeWithDOM('mount', () => {
expect(spy.calledWith(nextProps)).to.equal(true);
});

it('should merge newProps with oldProps', () => {
class Foo extends React.Component {
render() {
return (
<div {...this.props} />
);
}
}

const wrapper = mount(<Foo a="a" b="b" />);
expect(wrapper.props().a).to.equal('a');
expect(wrapper.props().b).to.equal('b');

wrapper.setProps({ b: 'c', d: 'e' });
expect(wrapper.props().a).to.equal('a');
expect(wrapper.props().b).to.equal('c');
expect(wrapper.props().d).to.equal('e');
});

});

describe('.setContext(newContext)', () => {
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/ShallowWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,25 @@ describe('shallow', () => {
expect(spy.calledWith(nextProps)).to.equal(true);
});

it('should merge newProps with oldProps', () => {
class Foo extends React.Component {
render() {
return (
<div {...this.props} />
);
}
}

const wrapper = shallow(<Foo a="a" b="b" />);
expect(wrapper.props().a).to.equal('a');
expect(wrapper.props().b).to.equal('b');

wrapper.setProps({ b: 'c', d: 'e' });
expect(wrapper.props().a).to.equal('a');
expect(wrapper.props().b).to.equal('c');
expect(wrapper.props().d).to.equal('e');
});

});

describe('.setContext(newContext)', () => {
Expand Down