Javascript 如何获取 jest 模拟函数中调用的参数?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41939511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:45:26  来源:igfitidea点击:

How can I get the arguments called in jest mock function?

javascriptjestjs

提问by Bruno Quaresma

How can I get the arguments called in jest mock function?

如何获取 jest 模拟函数中调用的参数?

I want inspect the object pass as argument.

我想检查对象传递作为参数。

回答by Bruno Quaresma

Just use mockObject.calls. In my case I used:

只需使用mockObject.calls。就我而言,我使用了:

const call = mockUpload.mock.calls[0][0]

Here's the documentation about the mockproperty

这是有关该属性文档mock

回答by Senthil Arumugam SP

Here is a simple way to assert the parameter passed.

这是断言传递的参数的简单方法。

expect(mockedFunction).toHaveBeenCalledWith("param1","param2");