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

expect(null).toEqual(jasmine.any(Object)) passes #1255

Closed
lmj0011 opened this issue Jan 15, 2017 · 4 comments
Closed

expect(null).toEqual(jasmine.any(Object)) passes #1255

lmj0011 opened this issue Jan 15, 2017 · 4 comments

Comments

@lmj0011
Copy link

lmj0011 commented Jan 15, 2017

version
jasmine v2.5.3
jasmine-core v2.5.2

environment
node v6.9.4
npm v3.10.10

running Jasmine
from cli using the jasmine command to run my tests

I'm expecting this to fail, but it doesn't.
How does null equal an Object?

expect(null).toEqual(jasmine.any(Object));

@lmj0011 lmj0011 changed the title expect(null).toEqual(jasmine.any(Object)) is true expect(null).toEqual(jasmine.any(Object)) passes Jan 15, 2017
@JamieMason
Copy link

JamieMason commented Jan 30, 2017

I think these lines in /src/core/asymmetric_equality/Any.js:26-28 could be the problem and the following snippet should be enough to fix it AFAICT.

    if (this.expectedObject == Object) {
      return Object.prototype.toString.call(other) == '[object Object]';
    }

@lmj0011
Copy link
Author

lmj0011 commented Jan 30, 2017

@JamieMason

I suppose in this context using == or === doesn't matter.
other than that, it looks legit.

you wanted to make the PR for this?

@JamieMason
Copy link

I suppose in this context using == or === doesn't matter.

Yeah I'd normally use === but I notice the rest of that file is using ==.

you wanted to make the PR for this?

I don't mind yeah, I'll try and fit it in today 👍

@slackersoft
Copy link
Member

I'm not sure if we can change this behavior for any right now, since that has a potential to break existing suites. That said, I think for 3.0 (when we can break things :), we'll want to look at the provided asymmetric matchers to ensure we are providing the right options out of the box.

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

No branches or pull requests

4 participants