Reputation: 566
I am currently testing a component which has a input field. These are my files:
Input.js
class Input extends React.Component {
render() {
return (
<input data-test="component-input" type="number" name="input-1" onChange={(e) => console.log(e.target.value)} />
);
}
}
Input-test.js
describe('INPUT', () => {
const wrapper = shallow(<Input />);
const input = wrapper.find({ 'data-test': 'component-input' });
it('renders without errors', () => {
expect(input.length).toEqual(1) &&
expect(input.length).toEqual(2);
});
});
The test passes however, I expected the test to fail because the it
block's callback function should return true
only when both of the conditions are satisfied. In this case, Jest tests the first assertion which is true
and does not seem to be testing the following assertion and gives a incorrect test result. Why is this happening?
Upvotes: 1
Views: 2574
Reputation: 160251
To write multiple expectations you do just that:
expect(input.length).toEqual(1)
expect(input.length).toEqual(2)
You're trying to use the return value of expect
, which is likely not what you believe it to be.
Upvotes: 4