Hello!
I have the following test setup, where Axios is being mocked with Jest while the rest of the services are mocked with typemoq:
it('Should return a rejected promise and record the error', async () => {
const axiosDeleteSpyOverMock = jest
.spyOn(axios, 'delete')
.mockImplementationOnce(async () => {
return Promise.reject(new Error(aErrorMessage));
});
try {
await axiosNetworkingClientWithCache.delete(
aService,
[],
aNetworkingClientOptionsNoSkipCache,
aData,
);
} catch (e) {
errorMonitoring.verify(
it => it.recordError(new Error(aErrorMessage), errorAttributes),
Times.once(),
);
apiCachedResponseManager.verify(
it => it.get(aService, [], []),
Times.never(),
);
apiCachedResponseManager.verify(
it => it.save(aService, [], [], anAxiosResponse.data),
Times.never(),
);
}
axiosDeleteSpyOverMock.mockRestore();
});
I have a problem with the verify method since it seems that it is not checking that the mocked fuctions are called with the passed arguments. For example, If I change errorAttributes, which is an object:
errorMonitoring.verify(
it => it.recordError(new Error(aErrorMessage), errorAttributes),
Times.once(),
);
to be a string (or any other thing):
errorMonitoring.verify(
it => it.recordError(new Error(aErrorMessage), "errorAttributes"),
Times.once(),
);
The test still passes. But if I change the assertion to be Times.never() it does fail as expected.
What am I doing worng?