Skip to content

Commit

Permalink
Improve readability of error message
Browse files Browse the repository at this point in the history
  • Loading branch information
davidblurton committed Oct 13, 2016
1 parent d04661d commit 1d3b1b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/renderers/shared/stack/reconciler/ReactCompositeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ StatelessComponent.prototype.render = function() {
return element;
};

function getTypeof(element) {
function getReadableTypeFor(element) {
if (element === null) {
return 'null';
}
if (Array.isArray(element)) {
return 'array';
return 'an array';
}
return typeof element;
}
Expand All @@ -64,7 +64,7 @@ function warnIfInvalidElement(Component, element) {
'%s(...): A valid React element (or null) must be returned, ' +
'but you returned %s.',
Component.displayName || Component.name || 'Component',
getTypeof(element)
getReadableTypeFor(element)
);
warning(
!Component.childContextTypes,
Expand Down Expand Up @@ -228,7 +228,7 @@ var ReactCompositeComponent = {
'%s(...): A valid React element (or null) must be returned, ' +
'but you returned %s.',
Component.displayName || Component.name || 'Component',
getTypeof(renderedElement)
getReadableTypeFor(renderedElement)
);
inst = new StatelessComponent(Component);
this._compositeType = CompositeTypes.StatelessFunctional;
Expand Down Expand Up @@ -1099,7 +1099,7 @@ var ReactCompositeComponent = {
'%s.render(): A valid React element (or null) must be returned, ' +
'but you returned %s.',
this.getName() || 'ReactCompositeComponent',
getTypeof(renderedElement)
getReadableTypeFor(renderedElement)
);

return renderedElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('ReactStatelessComponent', () => {
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'NotAComponent(...): A valid React element (or null) must be returned, ' +
'but you returned array.'
'but you returned an array.'
);
});

Expand Down Expand Up @@ -268,7 +268,7 @@ describe('ReactStatelessComponent', () => {
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'NotAComponent(...): A valid React element (or null) must be returned, ' +
'but you returned array.'
'but you returned an array.'
);
});
});

0 comments on commit 1d3b1b7

Please sign in to comment.