Skip to content

Commit 2cf8715

Browse files
author
Phillip Clark
authored
Merge pull request #90 from tdebarochez/master
Fix subject.toString is not a function
2 parents d4f4a4f + 211e36e commit 2cf8715

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
return 'array';
132132
} else if (Object.prototype.toString.call(subject) === '[object Date]') {
133133
return 'date';
134-
} else if (typeof subject.toString !== 'undefined' && /^\/.*\//.test(subject.toString())) {
134+
} else if (typeof subject.toString === 'function' && /^\/.*\//.test(subject.toString())) {
135135
return 'regexp';
136136
}
137137
return 'object';

test/tests.js

+19
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,23 @@ describe('deep-diff', function() {
532532
});
533533
});
534534

535+
describe('subject.toString is not a function', function() {
536+
var lhs = {
537+
left: 'yes',
538+
right: 'no',
539+
};
540+
var rhs = {
541+
left: {
542+
toString: true,
543+
},
544+
right: 'no',
545+
};
546+
547+
it('should not throw a TypeError', function() {
548+
var diff = deep.diff(lhs, rhs);
549+
550+
expect(diff.length).to.be(1);
551+
});
552+
});
553+
535554
});

0 commit comments

Comments
 (0)