Skip to content

Commit

Permalink
Merge pull request #170 from psfrankie/master
Browse files Browse the repository at this point in the history
fixed setProps execption swallowing issue and added regression test
  • Loading branch information
lelandrichardson committed Feb 7, 2016
2 parents 3c06ba1 + 3a23158 commit ac165c8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ReactWrapperComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function createWrapperComponent(node, options = {}) {

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

setChildContext(context) {
Expand Down
30 changes: 29 additions & 1 deletion src/__tests__/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,35 @@ describeWithDOM('mount', () => {
expect(wrapper.props().d).to.equal('e');
});

it('should throw if an exception occurs during render', () => {
class Trainwreck extends React.Component {
render() {
const { user } = this.props;
return (
<div>
{user.name.givenName}
</div>
);
}
}

const validUser = {
name: {
givenName: 'Brian',
},
};

const wrapper = mount(<Trainwreck user={validUser} />);

const setInvalidProps = () => {
wrapper.setProps({
user: {},
});
};

expect(setInvalidProps).to.throw();
});

});

describe('.setContext(newContext)', () => {
Expand Down Expand Up @@ -536,7 +565,6 @@ describeWithDOM('mount', () => {
});
});


describe('.mount()', () => {
it('should call componentWillUnmount()', () => {
const willMount = sinon.spy();
Expand Down

0 comments on commit ac165c8

Please sign in to comment.