Getter for Should syntax now uses valueOf for primitives #379
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While this PR doesn't fix a bug when Chai is used by itself, it does make it more compatible with babel and its core-js dependency (and possibly other ES6 transpilation tools).
The issue that led to this PR occurred when using the latest version of babel (and subsequently core-js). Our assertions involving Numbers would fail:
This would throw an error
AssertionError: expected {} to equal 1
when used with babel.After the update to babel and this error, we checked
shouldjs
and it did not exhibit this error. The reason for this, is thatshouldjs
usesvalueOf
for primitives instead of calling back into their constructors:core-js
is overwriting the Number prototype and constructor to support octal and binary (https://github.com/zloirock/core-js/commits/master/src/es6.number.constructor.js)I would be more than willing to attempt unit tests around how the existing implementation could break, but it is such an edge case and using
valueOf
is a common way to unwrap primitives. All tests (vianpm test
) in this repo passed with the change in place.We just spent the weekend and last few days switching our projects over from
shouldjs
to Chai because of how awesome it is. We love this project and I am happy to change this request as needed or to provide more information.