Skip to content

Commit

Permalink
[New] add enumerable properties to Function inspect result, per node’…
Browse files Browse the repository at this point in the history
…s `assert`
  • Loading branch information
ljharb committed Jul 31, 2020
1 parent 01ac3e4 commit fd38e1b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ module.exports = function inspect_(obj, options, depth, seen) {

if (typeof obj === 'function') {
var name = nameOf(obj);
return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']';
var keys = arrObjKeys(obj, inspect);
return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + keys.join(', ') + ' }' : '');
}
if (isSymbol(obj)) {
var symString = symToString.call(obj);
Expand Down
4 changes: 2 additions & 2 deletions test/fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ test('function name', function (t) {
var f = (function () {
return function () {};
}());
f.toString = function () { return 'function xxx () {}'; };
f.toString = function toStr() { return 'function xxx () {}'; };
var obj = [1, 2, f, 4];
t.equal(inspect(obj), '[ 1, 2, [Function (anonymous)], 4 ]');
t.equal(inspect(obj), '[ 1, 2, [Function (anonymous)] { toString: [Function: toStr] }, 4 ]');
});

test('anon function', function (t) {
Expand Down

2 comments on commit fd38e1b

@quanganhtran
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of an inconvenience than an actual issue but this breaks Enzyme snapshots which depend on shallowWrapper.debug().

@ljharb
Copy link
Member Author

@ljharb ljharb commented on fd38e1b Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enzyme doesn’t support or encourage snapshots; but please tag me on whatever issue you file on whatever you’re using for snapshots.

Please sign in to comment.