Skip to content

Commit

Permalink
Provides a descriptive error when simulating non-existent events, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cambridgemike committed Jan 12, 2016
1 parent ba911a0 commit 6389d93
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,14 @@ export default class ReactWrapper {
* @returns {ReactWrapper}
*/
simulate(event, ...args) {
this.single(n => Simulate[event](findDOMNode(n), ...args));
this.single(n => {
const eventFn = Simulate[event];
if (!eventFn) {
throw new TypeError(`ReactWrapper::simulate() event '${event}' does not exist`);
}

eventFn(findDOMNode(n), ...args);
});
return this;
}

Expand Down
6 changes: 5 additions & 1 deletion src/__tests__/ReactWrapper-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ describeWithDOM('mount', () => {

});


it('should pass in event data', () => {
const spy = sinon.spy();
class Foo extends React.Component {
Expand All @@ -359,6 +358,11 @@ describeWithDOM('mount', () => {
expect(spy.args[0][0].someSpecialData).to.equal('foo');
});

it('should throw a descriptive error for invalid events', () => {
const wrapper = mount(<div>foo</div>);
expect(wrapper.simulate.bind(wrapper, 'invalidEvent'))
.to.throw(TypeError, "ReactWrapper::simulate() event 'invalidEvent' does not exist");
});
});

describe('.setState(newState)', () => {
Expand Down

0 comments on commit 6389d93

Please sign in to comment.