我有一个包含步骤的向导,每个步骤都有自己的验证(同步/异步)。
例如:
<Wizard>
<Form1 />
<Form2 />
<Form3 />
</ Wizard>
Run Code Online (Sandbox Code Playgroud)
每个表单都包含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);
};
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试测试向导的行为,方法是确保单击“继续”时步骤编号增加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);
});
Run Code Online (Sandbox Code Playgroud)
运行测试后,出现如下错误: …