-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructor error message #11395
Constructor error message #11395
Conversation
name, | ||
); | ||
|
||
if (type.prototype && type.prototype.render !== undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's remove this newline
ReactTestUtils.renderIntoDocument(<RenderTestUndefinedRender />); | ||
}).toThrow(); | ||
|
||
const error = console.error.calls.mostRecent().args[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same feedback
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.