Skip to content

Commit

Permalink
inspect: correctly handle custom objects without class name
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Aug 2, 2019
1 parent ce8b4cd commit ae9e34b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/jsutils/__tests__/inspect-test.js
Expand Up @@ -177,5 +177,10 @@ describe('inspect', () => {

(Foo.prototype: any)[Symbol.toStringTag] = 'Bar';
expect(inspect([[new Foo()]])).to.equal('[[[Bar]]]');

const objectWithoutClassName = new (function() {
this.foo = 1;
})();
expect(inspect([[objectWithoutClassName]])).to.equal('[[[Object]]]');
});
});
2 changes: 1 addition & 1 deletion src/jsutils/inspect.js
Expand Up @@ -117,7 +117,7 @@ function getObjectTag(object) {

if (tag === 'Object' && typeof object.constructor === 'function') {
const name = object.constructor.name;
if (typeof name === 'string') {
if (typeof name === 'string' && name !== '') {
return name;
}
}
Expand Down

0 comments on commit ae9e34b

Please sign in to comment.