From 3a23158668d643101e86de8f2dcaa1b07b1a4af6 Mon Sep 17 00:00:00 2001 From: Frankie O'Rourke Date: Sat, 6 Feb 2016 19:52:58 -0800 Subject: [PATCH] fixed setProps execption swallowing issue and added regression test --- src/ReactWrapperComponent.jsx | 2 +- src/__tests__/ReactWrapper-spec.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/ReactWrapperComponent.jsx b/src/ReactWrapperComponent.jsx index 520f5201d..a599be69d 100644 --- a/src/ReactWrapperComponent.jsx +++ b/src/ReactWrapperComponent.jsx @@ -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) { diff --git a/src/__tests__/ReactWrapper-spec.js b/src/__tests__/ReactWrapper-spec.js index 827bb4abc..f322a79ea 100644 --- a/src/__tests__/ReactWrapper-spec.js +++ b/src/__tests__/ReactWrapper-spec.js @@ -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 ( +
+ {user.name.givenName} +
+ ); + } + } + + const validUser = { + name: { + givenName: 'Brian', + }, + }; + + const wrapper = mount(); + + const setInvalidProps = () => { + wrapper.setProps({ + user: {}, + }); + }; + + expect(setInvalidProps).to.throw(); + }); + }); describe('.setContext(newContext)', () => { @@ -536,7 +565,6 @@ describeWithDOM('mount', () => { }); }); - describe('.mount()', () => { it('should call componentWillUnmount()', () => { const willMount = sinon.spy();