close

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

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How can I get the arguments called in jest mock function? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

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

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

    can I get the arguments called in jest mock function Here is a simple way to assert the parameter passed.
    expect(mockedFunction).toHaveBeenCalledWith("param1","param2");

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

    can I get the arguments called in jest mock function Here is a simple way to assert the parameter passed.
    expect(mockedFunction).toHaveBeenCalledWith("param1","param2");

Method 1

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

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

Method 2

Here is a simple way to assert the parameter passed.

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

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment