Deep equal with symbols as keys does not fail
See original GitHub issueHi,
The following test should fail but doesn’t:
let test = Symbol('test')
expect({[test]: 1}).to.deep.equal({[test]: 2})
Thanks! Florent
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:18 (8 by maintainers)
Top Results From Across the Web
object - Javascript - deepEqual Comparison - Stack Overflow
Write a function, deepEqual, that takes two values and returns true only if they are the same value or are objects with the...
Read more >Expect / Should - Chai Assertion Library
Target object deeply (but not strictly) equals `{a: 1}` expect({a: 1}).to.deep.equal({a: ... Properties with Symbol-based keys are excluded from the count.
Read more >Equality comparisons and sameness - JavaScript | MDN
If the values have different types, the values are considered unequal. If the values have the same type, are not numbers, and have...
Read more >But Why?. Symbols, the newest JavaScript… | by ... - Medium
In this case a symbols is similar to an object as creating multiple instances will result in values which are not exactly equal....
Read more >Assert | Node.js v19.3.0 Documentation
If the values are not equal, an AssertionError is thrown with a message property set equal to the value of the message parameter....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a simple workaround: Node.js
util.inspect
Example:
@shvaikalesh Hi. I have one real-world use case for symbols. Sequelize module recently implemented their operators using Symbols, since it’s more secure ( http://docs.sequelizejs.com/manual/tutorial/querying.html#operators ). Now, it’s much more tedious to write unit tests, in order to test these operators. It’s still possible, but quite challenging.
Check this. this is how it could look if chai would assert Symbols correctly:
( All the values inside
Op
are symbols.)But, now, in order to test this, i have to do some totally crazy stuff.