In my angular-cli project, I have a set of Jasmine tests that include various assertions. One particular assertion looks like this:
expect(dispatchSpy).toHaveBeenCalledWith({
type: 'SET_RANGE', payload: { value: 'Weekly', start: moment('2017-04-24'), end: moment() }
});
However, upon running the test, I encounter the following error message:
Expected spy dispatch to have been called with [ Object({ type: 'SET_RANGE', payload: Object({ value: 'Weekly', start: Mon Apr 24 2017 00:00:00 GMT+0100, end: Sat Apr 29 2017 00:00:00 GMT+0100 }) }) ] but actual calls were [ Object({ type: 'SET_RANGE', payload: Object({ value: 'Weekly', start: Mon Apr 24 2017 00:00:00 GMT+0100, end: Sat Apr 29 2017 00:00:00 GMT+0100 }) }) ]
This issue seems to stem from mismatched properties within the momentJS object. In other scenarios, I've resolved similar problems by comparing formatted date values like so:
expect(moment('2017-01-01').format()).toEqual(moment('2017-01-01').format())
Unfortunately, when using ).toHaveBeenCalledWith(
, I can't implement the same format()
method. Any ideas on how to approach this situation?