Skip to content

Commit

Permalink
Add test for cb error if not function
Browse files Browse the repository at this point in the history
  • Loading branch information
alecrobins committed Oct 2, 2016
1 parent 729240a commit 5a2fe98
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/ReactWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,44 @@ describeWithDOM('mount', () => {
expect(wrapper.state()).to.eql({ id: 'bar' });
});
});

it('should throw error when cb is not a function', () => {
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = { id: 'foo' };
}
render() {
return (
<div className={this.state.id} />
);
}
}
const wrapper = mount(<Foo />);
expect(wrapper.state()).to.eql({ id: 'foo' });
expect(() => wrapper.setState({ id: 'bar' }, 1)).to.throw(Error);
});

itIf(REACT15, 'should throw error when cb is not a function', () => {
class Foo extends React.Component {
constructor(props) {
super(props);
this.state = { id: 'foo' };
}
render() {
return (
<div className={this.state.id} />
);
}
}
const wrapper = mount(<Foo />);
expect(wrapper.state()).to.eql({ id: 'foo' });
expect(() => wrapper.setState({ id: 'bar' }, 1)).to.throw(
Error,
'setState(...): Expected the last optional `callback` argument ' +
'to be a function. Instead received: number.'
);
});
});

describe('.is(selector)', () => {
Expand Down

0 comments on commit 5a2fe98

Please sign in to comment.