Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.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 使用Tohaven调用时对Jest测试错误作出反应_Reactjs_Jestjs_Enzyme - Fatal编程技术网

Reactjs 使用Tohaven调用时对Jest测试错误作出反应

Reactjs 使用Tohaven调用时对Jest测试错误作出反应,reactjs,jestjs,enzyme,Reactjs,Jestjs,Enzyme,我是在开玩笑,但是我不能回避下面的错误。expectdummyFunction.ToHaveEndCalledWith不是函数 除非我遗漏了什么,否则我非常肯定我的dummyFunction设置是正确的。在测试中使用dummyFunction之前,我甚至对它的输出进行了处理,这就是输出 dummyFunction控制台.log输出 已通过测试收集 提前感谢您的帮助。ToHavenCalledWith是在Jest版本中发布的,因此如果您使用的是早期版本的Jest,您将看到该错误 请注意,ToHav

我是在开玩笑,但是我不能回避下面的错误。expectdummyFunction.ToHaveEndCalledWith不是函数

除非我遗漏了什么,否则我非常肯定我的dummyFunction设置是正确的。在测试中使用dummyFunction之前,我甚至对它的输出进行了处理,这就是输出

dummyFunction控制台.log输出

已通过测试收集

提前感谢您的帮助。

ToHavenCalledWith是在Jest版本中发布的,因此如果您使用的是早期版本的Jest,您将看到该错误

请注意,ToHaveBeennCalledWith仅此而已,如果您使用的是早期版本的Jest,则可以执行以下操作:

const dummyFunction = jest.fn();

dummyFunction({ foo: 'bar' });
dummyFunction({ please: 'work' });

expect(dummyFunction).toHaveBeenCalledTimes(2); // pass

expect(dummyFunction.mock.calls[0]).toEqual([{ foo: 'bar' }]); // pass
expect(dummyFunction.mock.calls[1]).toEqual([{ please: 'work' }]); // pass

函数名似乎不正确,是不是应该用tobeennthCalledWith而不是tobeenCallednthWith?对不起,我之前尝试了不同的方法,复制了错误的版本。即使拼写正确,我也有问题。谢谢Brian,原来我使用的是Jest版本20.0.4。非常感谢您抽出时间向我展示如何在旧版本上使用它。@不客气,很高兴听到它很有用!
const dummyFunction = jest.fn();

expect(dummyFunction).toHaveBeenCalledTimes(2); // pass

expect(dummyFunction).toHaveBeenNthCalledWith(1, { foo: 'bar' }); // error
expect(dummyFunction).toHaveBeenNthCalledWith(2, { please: 'work' });
const dummyFunction = jest.fn();

dummyFunction({ foo: 'bar' });
dummyFunction({ please: 'work' });

expect(dummyFunction).toHaveBeenCalledTimes(2); // pass

expect(dummyFunction.mock.calls[0]).toEqual([{ foo: 'bar' }]); // pass
expect(dummyFunction.mock.calls[1]).toEqual([{ please: 'work' }]); // pass