Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should.equal fails when comparing dates #63

Closed
ericchaves opened this issue Apr 26, 2012 · 3 comments
Closed

should.equal fails when comparing dates #63

ericchaves opened this issue Apr 26, 2012 · 3 comments

Comments

@ericchaves
Copy link

Hi guys,

Using should.equal with Date objects seems to be failing.

var date = new Date();
date.should.equal(date);

AssertionError: expected 1335443601886 to equal Thu, 26 Apr 2012 12:33:21 GMT

This happens because "should" value (the actual value) is obtained using the valueOf() function (should.js line 81) and the "equal" function does not follow the same approach, comparing the valufOf(actual) with the actual object directly (should.js line 303). In case of date objects since valueOf returns a number the equality fails.

I fix it by performing the same process of value comparison changing the equal function to (line 303):

        Object(val).valueOf() === this.obj

Not sure if this has broader implication on the framework thou.

Cheers,

Eric

@tj tj closed this as completed in f214f66 Apr 26, 2012
@c4milo
Copy link

c4milo commented Feb 8, 2013

I'm using v1.2.1 and running into this same problem.

@ben-lin
Copy link

ben-lin commented Feb 19, 2013

same here, v1.2.1

@zerobase
Copy link

zerobase commented Nov 2, 2013

@c4milo @ben-lin
I use eql instead of equal (strict equal).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants