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

Symbols in objects and toEqual #3347

Closed
alondahari opened this issue Apr 21, 2017 · 3 comments · Fixed by #3437
Closed

Symbols in objects and toEqual #3347

alondahari opened this issue Apr 21, 2017 · 3 comments · Fixed by #3437

Comments

@alondahari
Copy link

alondahari commented Apr 21, 2017

Hi,
Current behavior:

const sym = Symbol('dude')
const obj1 = { [sym]: 'one' }
const obj2 = { [sym]: 'two' }

expect(obj1).toBe(obj1) // fail
expect(obj1).toEqual(obj1) // pass
expect(obj1).toEqual(obj2) // pass!

expected behavior:

expect(obj1).toBe(obj1) // fail
expect(obj1).toEqual(obj1) // pass
expect(obj1).toEqual(obj2) // fail

Thanks!

@pedrottimark
Copy link
Contributor

As first step to dig into this, all three assertions pass in Jasmine 2.6.0

@jazzdragon Help me understand why expected result of expect(obj1).toBe(obj1) is fail?

console.log(obj1 === obj1); // true in Node 7.9.0

Concerning toEqual a for-in loop in keys helper function does not enumerate symbols at:

Before going any farther, are we willing to call Object.getOwnPropertySymbols also?

For more information:

@alondahari
Copy link
Author

My bad, what I really meant is this setup:

const sym = Symbol('dude')
const obj1 = { [sym]: 'one' }
const obj2 = { [sym]: 'two' }
const obj3 = { [sym]: 'one' }

and then:

expect(obj1).toBe(obj3) // fail - good
expect(obj1).toEqual(obj3) // pass - good
expect(obj1).toEqual(obj2) // pass - no good!

Sorry for the confusion. I wouldn't normally test an object against itself, but against another one with the same structure...

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants