Constructor error message#11395
Constructor error message#11395gaearon merged 9 commits intofacebook:masterfrom dylanapplegate:constructor-error-message
Conversation
| name, | ||
| ); | ||
|
|
||
| if (type.prototype && type.prototype.render !== undefined) { |
There was a problem hiding this comment.
Let's put the whole thing into if (!renderPresent) so we don't run those checks unnecessarily. And make it warning(false.
| warning( | ||
| false, | ||
| '%s(...): No `render` method found on the returned component ' + | ||
| 'instance: is the `constructor` defined well?', |
There was a problem hiding this comment.
Let's be explicit: "did you accidentally return an object from the constructor"
|
Do you mind writing a test inside |
|
Sure thing! I'll have an updated PR over later today. |
| ReactTestUtils.renderIntoDocument(<RenderTextInvalidConstructor />); | ||
| }).toThrow(); | ||
|
|
||
| const error = console.error.calls.mostRecent().args[0]; |
There was a problem hiding this comment.
Let's also assert we only emit one warning. Like other tests do by asserting on count.
| }).toThrow(); | ||
|
|
||
| const error = console.error.calls.mostRecent().args[0]; | ||
|
|
There was a problem hiding this comment.
Nit: let's remove this newline
| ReactTestUtils.renderIntoDocument(<RenderTestUndefinedRender />); | ||
| }).toThrow(); | ||
|
|
||
| const error = console.error.calls.mostRecent().args[0]; |
|
Looks great. Thanks! |
|
@gaearon No problem! Do you have any recommendations for my next issue? Maybe something a little more difficult? |
|
Adding Flow coverage to files that don't currently have it (and fixing Flow errors) would be greatly appreciated. |
|
Yep, I'm game for adding flow coverage. Is there a list I can work from? Also, would you want a PR for each file? |
|
No particular list, but you can go through packages and do this in the order you see files without |
|
Understood! I'll get a PR over with the first set by the weekend, maybe sooner. |
|
There's a few older PRs that I haven't gotten to reviewing yet, so this will take a little more time. I'm also on vacation next week. I'll likely pick it up after that! |
* Constructor test and fix complete * Linters and prettier run * Remove unnecessary checks * Update error message * Updat unit test * prettier * Tweak the check to be more specific * Move tests to ReactCompositeComponent-test * add error call count and remove line
Addresses #11381.