chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

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?

asked by pablo (600 points)

1 Answer

0 votes

Hey Pablo,

I believe you might have mistaken typemoq (a mocking library for JavaScript) with our product, Typemock Isolator (a mocking and unit testing solution for .NET) or Isolator++ (for C++). surprise

answered by Erel_TypeMock (2.6k points)
...