我正在测试金额等于特定字符串的第三个条件状态错误,但是当我运行它时,我得到一个空字符串。
条件:
if (!this.state.amount) {
this.setState(() => ({ error: 'Please provide amount.' }));
}
Jest测试案例:
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.');
});
错误数组索引:
id: '5',
description: 'Gas',
note: '',
amount: '',
createdAt: moment(0).add(4, 'days').valueOf()
理想情况下,这种情况应该测试金额等于“#”的状态。并提供错误信息&#39;请提供金额。&#39;