【发布时间】:2019-08-21 16:26:42
【问题描述】:
我有一个包含步骤的向导,每个步骤都有自己的验证(同步/异步)。
例如:
<Wizard>
<Form1 />
<Form2 />
<Form3 />
</ Wizard>
每个表单都包含验证表单输入的onContinue 方法。
onContinue = async () => {
let step = this.steps[this.state.step];
let validation = await step.validate();
// check for error and change step number.
this.changeStep(this.state.step + 1, validation);
};
现在我正在尝试测试向导的行为,方法是确保在单击继续时,步骤编号增加 1。
it('should set the state property "step" to 1 after successfully clicking the continue button', () => {
const props = {
id: 'testId',
children: noErrorChildren
};
const wizard= mount(<Wizard {...props} />);
tree.find('onContinue-button').simulate('click');
expect(wizard.state().step).toEqual(1);
});
运行测试后出现这个错误:
Error: expect(received).toEqual(expected)
Expected value to equal:
1
Received:
0
Expected :1
Actual :0
step 变量未按预期增加到 1。
谢谢。
【问题讨论】:
-
onContinue是什么?是onClick={onContinue}吗? -
@AlexandrZavalii 是的没用