Skip to content

Commit

Permalink
fix: custom instOfHandler result should be cast to boolean (#10197)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and nicolo-ribaudo committed Jul 10, 2019
1 parent 4eab157 commit e88a569
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-helpers/src/helpers.js
Expand Up @@ -587,7 +587,7 @@ helpers.wrapNativeSuper = helper("7.0.0-beta.0")`
helpers.instanceof = helper("7.0.0-beta.0")`
export default function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return right[Symbol.hasInstance](left);
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
Expand Down
Expand Up @@ -4,6 +4,11 @@ foo[Symbol.hasInstance]= function () { return true; };
var bar = {};

expect(bar instanceof foo).toBe(true);

var qux = {};
qux[Symbol.hasInstance]= function () { return NaN };
expect(bar instanceof qux).toBe(false);

expect(new String).toBeInstanceOf(String);

//
Expand Down

0 comments on commit e88a569

Please sign in to comment.