2

I am in the process of unit testing a function using Jest that merely passes on its parameters to another function by calling it and has no return.

I have googled and tried a bunch of suggested mock implementations, but can't seem to get it to work.

Imported File:

export const firstFunc = (dataObj) => {
  secondFunc('anything', dataObj)
}

export const secondFunc = (str, dataObj) => {
  // Does something with the dataObj but also doesn't return anything.
}

Essentially what I want to test for is that firstFunc calls secondFunc, but am not able to get it to work.

Thank you in advance. Also, open to suggestions for any other tests that I could run in this situation.

skyboyer
  • 22,209
  • 7
  • 57
  • 64
SavSamoylov
  • 65
  • 1
  • 2
  • 7

1 Answers1

3

As far as I understood your problem, you could have two solutions.

Firstly, add return value after calling function, and export it to tests.

Secondly, you could use sinon js with jest.

Spying on an imported function that calls another function in Jest