sinon icon indicating copy to clipboard operation
sinon copied to clipboard

sinon.deepEqual(new Date(0), new Date()) returns true.

Open faridnsh opened this issue 14 years ago • 13 comments

sinon.deepEqual returns true for every two dates, even if they don't match.

I found out this problem, when my mock expectation didn't throw when it was called with the wrong date.

faridnsh avatar Nov 04 '12 16:11 faridnsh

This is how they are handled in underscore(and almost same in lodash) https://github.com/documentcloud/underscore/blob/master/underscore.js#L832-837. Looking at the code, seems like we also lack for the check of other native classes.

faridnsh avatar Nov 04 '12 16:11 faridnsh

The next version of Sinon will replace it's deepEqual with that of Samsam, which does not have this problem.

cjohansen avatar Nov 05 '12 09:11 cjohansen

That would be awesome.

faridnsh avatar Nov 05 '12 10:11 faridnsh

How are you going to put the matchers support in deepEqual then?

mantoni avatar Nov 06 '12 10:11 mantoni

I don't quite remember, but samsam either supports or will soon support custom check hooks. I don't intend to break anything :)

cjohansen avatar Nov 06 '12 11:11 cjohansen

I saw a match function in samsam that is quite similar to sinon.match. You could also move the matchers into samsam entirely. That would also provide that custom check hook.

mantoni avatar Nov 06 '12 13:11 mantoni

Yeah, that match is the gut of Buster's assert.match, which works a little differently. But having it support the Sinon matchers as well would probably be a good idea. I'll look into it when integrating the two.

cjohansen avatar Nov 06 '12 16:11 cjohansen

Hi, everybody. I don't quite understand, why this issue is closed, deepEqual still behaves incorrectly as of 1.7.1. Here is the test case:

var foo = function(date){};
var spy = sinon.spy(foo);
spy(new Date(2013, 4, 28, 10, 27, 51));
sinon.assert.calledWithExactly(spy, new Date(2012, 4, 28, 10, 27, 51)); // <-- will not fail

gserebryanskyi avatar May 29 '13 07:05 gserebryanskyi

Yeah. Too much enthusiasm on our side to use samsam which will most certainly not happen in 1.x. Reopening. Care to provide a patch?

mantoni avatar May 29 '13 07:05 mantoni

Ok, I'll try to submit a patch later today.

gserebryanskyi avatar May 29 '13 08:05 gserebryanskyi

Fixed by @gserebryanskyi in #289

mantoni avatar May 30 '13 09:05 mantoni

Is there any way to correctly check deep equality of dates in a call to spy.calledWithExactly?

troynguyen8 avatar May 09 '19 21:05 troynguyen8

It should just work™️. If you have an issue with dates and calledWithExactly, please open a new issue with a description stating what you expect to happen and what actually happens. If you have a usage question, it's probably best to post your question on StackOverflow using the Sinon tag. Thanks.

mantoni avatar May 10 '19 09:05 mantoni