Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 预期模拟函数被调用了一次,但调用了零次。反应_Reactjs_Jestjs_Enzyme - Fatal编程技术网

Reactjs 预期模拟函数被调用了一次,但调用了零次。反应

Reactjs 预期模拟函数被调用了一次,但调用了零次。反应,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,我已经检查了所有的堆栈溢出问题。我解决不了这个问题我是个新开玩笑的人 单元测试 const testValues = { Promo_Code: "FOO", onSubmit: jest.fn() }; it("Submit works", () => { const component = shallow( <Create.WrappedComponent {...testValues} /&g

我已经检查了所有的堆栈溢出问题。我解决不了这个问题我是个新开玩笑的人 单元测试

const testValues = {
    Promo_Code: "FOO",
    onSubmit: jest.fn()
  };

it("Submit works", () => {
    const component = shallow(
        <Create.WrappedComponent {...testValues} />
    );
    component.find("#submitButton").simulate("submit");
    expect(testValues.onSubmit).toHaveBeenCalledTimes(1);
    expect(testValues.onSubmit).toBeCalledWith({
        username: testValues.username,
        password: testValues.password
    });
});
const testValues={
促销代码:“FOO”,
onSubmit:jest.fn()
};
它(“提交作品”,()=>{
常数分量=浅(
);
component.find(“#submitButton”).simulate(“submit”);
expect(testValues.onSubmit).tohavebeincalledtimes(1);
expect(testValues.onSubmit).toBeCalledWith({
用户名:testValues.username,
密码:testValues.password
});
});

错误:-预期模拟函数已被调用一次,但调用了零次。

请尝试以下方法

component.find('form').simulate('submit', { preventDefault () {} });
[或]

component.find('form').props().onSubmit();