What is the equivalent of sinonStub.callsArg(2).returns({}) in Jest?

21 Views Asked by At

Some code we've inherited from a supplier is using

uploadStub.callsArg(2).returns({})

in Sinon to mock out the callback to a stubbed function. We're migrating to Jest and I'm struggling to find an equivalent.

The original function call being

Upload(req, res, async function (error) { ... })

It's this third arg which is a callback that I want to become a mock so the test can return an actual value.

jestcodemods has this PR which suggests

apiStub.mockImplementation((...args) => args[2]())

which would call the callback but not create a mocked version of it.

1

There are 1 best solutions below

0
Paul Solecki On

So, it turns out the jestcodemods solution works with no need to make it return a value.