[ES6] should.equal fails for Symbols
See original GitHub issueHallo 😄
I ran into this small issue while testing Symbol equality using the should
syntax:
let prince = Symbol("Love");
expect(prince).to.equal(prince); // Passes
prince.should.equal(prince); // AssertionError: expected {} to equal {}
Adding || this instanceof Symbol
to the shouldGetter resolved the issue. I’m not sure if a PR is desired since it’s ES6-specific?
Thanks!
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Equality (==) - JavaScript - MDN Web Docs
The equality ( == ) operator checks whether its two operands are equal, returning a Boolean result. Unlike the strict equality operator, ...
Read more >What is the motivation for bringing Symbols to ES6?
The original motivation for introducing symbols to Javascript was to enable private properties. Unfortunately, they ended up being severely ...
Read more >Metaprogramming in ES6: Symbols and why they're awesome
Symbols will never conflict with Object string keys. · Symbols cannot be read using existing reflection tools. · Symbols are not private.
Read more >Understanding symbols in JavaScript - LogRocket Blog
Starting with ES6, symbols were added to the primitives group. ... using the factory function Symbol() , their values will not be equal....
Read more >A practical guide to ES6 Symbol - codeburst
While the example above could be achieved without Symbols (either as its own method or by overwriting String.prototype ), there are well-known ...
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
Sounds good 😄
I’ll submit a PR after work today if it’s still open then.
Edit: Working on this now.
Yeah… you raise a good point here. This could be potentially dangerous for that exact reason actually. Probably best just to add the extra Symbol code there, as per your original comment. In fact we could handle it a bit easier by doing
typeof this === 'symbol'
- seeing as every browser that supports Symbols also supportstypeof Symbol() === 'symbol'
.Absolutely.
I’ll mark this as PR wanted - based on the following criteria:
should