Skip to content

Commit ac165c8

Browse files
Merge pull request #170 from psfrankie/master
fixed setProps execption swallowing issue and added regression test
2 parents 3c06ba1 + 3a23158 commit ac165c8

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/ReactWrapperComponent.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default function createWrapperComponent(node, options = {}) {
3434

3535
setChildProps(newProps) {
3636
const props = objectAssign({}, this.state.props, newProps);
37-
return new Promise(resolve => this.setState({ props }, resolve));
37+
this.setState({ props });
3838
},
3939

4040
setChildContext(context) {

src/__tests__/ReactWrapper-spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,35 @@ describeWithDOM('mount', () => {
508508
expect(wrapper.props().d).to.equal('e');
509509
});
510510

511+
it('should throw if an exception occurs during render', () => {
512+
class Trainwreck extends React.Component {
513+
render() {
514+
const { user } = this.props;
515+
return (
516+
<div>
517+
{user.name.givenName}
518+
</div>
519+
);
520+
}
521+
}
522+
523+
const validUser = {
524+
name: {
525+
givenName: 'Brian',
526+
},
527+
};
528+
529+
const wrapper = mount(<Trainwreck user={validUser} />);
530+
531+
const setInvalidProps = () => {
532+
wrapper.setProps({
533+
user: {},
534+
});
535+
};
536+
537+
expect(setInvalidProps).to.throw();
538+
});
539+
511540
});
512541

513542
describe('.setContext(newContext)', () => {
@@ -536,7 +565,6 @@ describeWithDOM('mount', () => {
536565
});
537566
});
538567

539-
540568
describe('.mount()', () => {
541569
it('should call componentWillUnmount()', () => {
542570
const willMount = sinon.spy();

0 commit comments

Comments
 (0)