So I have a module called A with two functions:
function handleCreatedOrder(){
console.log("here")
}
function acquireOrder(){
if(condition) handleCreatedOrder
}
I have a test which needs to check if handleCreatedOrder is getting called. I have mocked the module by first importing the module import * as acquireOrderWrapper from './module'
Then in the test I am spying on the module by let handleCreatedOrderSpy = jest.spyOn(acquireOrderWrapper, "handleCreatedOrder")
When I try to assert expect(handleCreatedOrder).toBeCalled()
it fails because the received number of calls does not match. I understand this is because the mocking is not proper as the console.log from handleCreatedOrder
is called but the expect statement fails. What am I doing wrong?
My tests are currently like
describe("handle acquireOrder success responses", () => {
const reactRedux = { useDispatch, useSelector }
const useDispatchMock = jest.spyOn(reactRedux, "useDispatch")
test("test1", async () => {
let handleCreatedOrderSpy = jest.spyOn(acquireOrderWrapper, "handleCreatedOrder")
await acquireOrder()
expect(handleCreatedOrderSpy).toBeCalled()
}