How can I get the arguments called in jest mock fu

2020-05-24 19:17发布

问题:

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

I want inspect the object pass as argument.

回答1:

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

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

Here's the documentation about the mock property



回答2:

Here is a simple way to assert the parameter passed.

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