I am testing for the third conditional state error of the amount to equal a specific string, but when I run it I get an empty string.
Conditional:
if (!this.state.amount) {
this.setState(() => ({ error: 'Please provide amount.' }));
}
Jest Test Case:
test('should render error for lack of amount', () => {
const onSubmitSpy = jest.fn();
const wrapper = shallow(<ExpenseForm expense={errors[1]} onSubmit={onSubmitSpy} />);
expect(wrapper).toMatchSnapshot();
wrapper.find('form').simulate('submit', {
preventDefault: () => { },
});
expect(wrapper).toMatchSnapshot();
console.log(wrapper.state('error'));
expect(wrapper.state('error')).toBe('Please provide amount.');
});
Error array index:
id: '5',
description: 'Gas',
note: '',
amount: '',
createdAt: moment(0).add(4, 'days').valueOf()
Ideally, this condition should test for the amount state to equal '' and give the error message of 'Please provide amount.'
Aucun commentaire:
Enregistrer un commentaire