I am trying to test a function that returns a moment Object to see if it is returning the correct time, when I try to do something like this:
const moment = require('moment');
const setsTime = (testFn) => {
testFn(moment.utc('2020-01-01'));
};
test('sets Correct time', () => {
const mockFn = jest.fn();
setsTime(mockFn);
expect(mockFn).toHaveBeenCalledWith('2020-01-01T00:00:00.000Z');
});
I get:
expect(jest.fn()).toHaveBeenCalledWith(...expected)
Expected: "2020-01-01T00:00:00.000Z"
Received: "2020-01-01T00:00:00.000Z"
How do I solve this? if I put moment.utc('2020-01-01T00:00:00.000Z')
in the toHaveBeenCalledWith
section I still don’t get the match as the received section just becomes the huge moment object.
1