Skip to content

Commit

Permalink
[Fix] improve error message when callability is mismatched
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Oct 5, 2023
1 parent fa8d0ae commit dc0f577
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/why.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ test('arrays', function (t) {
});

test('objects', function (t) {
t.test('fake toStringTag', { skip: !symbolToStringTag }, function (st) {
var fake = function () {};
fake[symbolToStringTag] = 'Object';

st.equal(isEqualWhy({}, fake), 'second argument is callable; first is not');
st.equal(isEqualWhy(fake, {}), 'first argument is callable; second is not');

st.end();
});

t.test('prototypes', function (st) {
var F = function F() {
this.foo = 42;
Expand Down
3 changes: 3 additions & 0 deletions why.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ module.exports = function whyNotEqual(value, other) {
var valueIsCallable = isCallable(value);
var otherIsCallable = isCallable(other);
if (valueIsCallable || otherIsCallable) {
if (valueIsCallable !== otherIsCallable) {
return valueIsCallable ? 'first argument is callable; second is not' : 'second argument is callable; first is not';
}
if (functionsHaveNames && whyNotEqual(value.name, other.name) !== '') {
return 'Function names differ: "' + value.name + '" !== "' + other.name + '"';
}
Expand Down

0 comments on commit dc0f577

Please sign in to comment.