Skip to content

Commit

Permalink
[Fix] Make displayNameOfNode return function.name even if it is falsy
Browse files Browse the repository at this point in the history
- previously it would return the function itself
  • Loading branch information
nfcampos authored and ljharb committed Apr 10, 2017
1 parent c8f2185 commit 85447ed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,5 @@ export function displayNameOfNode(node) {

if (!type) return null;

return type.displayName || (typeof type === 'function' ? functionName(type) : type.name) || type;
return type.displayName || (typeof type === 'function' ? functionName(type) : type.name || type);
}
8 changes: 8 additions & 0 deletions test/Utils-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ describe('Utils', () => {
expect(displayNameOfNode(<Foo />)).to.equal('Foo');
});

it('should return the name even if it is falsy', () => {
const makeFoo = () => () => <div />;

const Foo = makeFoo();

expect(displayNameOfNode(<Foo />)).to.equal('');
});

describeIf(!REACT013, 'stateless function components', () => {
it('should return the name', () => {
const Foo = () => <div />;
Expand Down

0 comments on commit 85447ed

Please sign in to comment.