-
-
Notifications
You must be signed in to change notification settings - Fork 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
Throw when mount/shallow rendering invalid root elements #1759
Throw when mount/shallow rendering invalid root elements #1759
Conversation
0856e7f
to
b3d34b4
Compare
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.
Thanks, this looks great!
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.
This will actually need a rebase
@@ -85,8 +85,13 @@ class ReactWrapper { | |||
const options = makeOptions(passedOptions); | |||
|
|||
if (!root) { | |||
const adapter = getAdapter(options); | |||
if (!adapter.isValidElement(nodes)) { |
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.
hmm, nodes
could be an array of valid elements; i'm not sure we can check it directly.
also, i think we probably want to check this on root
too if that's provided?
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.
I think if we try to mount
an array of elements as the root that should still throw.
root
elements should always have already been through this path when they were created, ie wrap
/ReactWrapper
constructor only get called with null
when mounting (or diving in the shallow wrapper) or this[ROOT]
when traversing, which is only set here.
473c67e
to
4324666
Compare
The tests added failed previously with
for the mount tests and
for the shallow tests |
4324666
to
997f95a
Compare
- [New] Add forwardRef support (#1592, @jquense) - [New] Add Portal support (#1760, #1761, #1772, #1774, @jgzuke) - [New] Add pointer events support (#1753, @ljharb) - [Fix] preemptively fix compat with React v16.4.3 (#1790, #1778, @gaearon, @aweary) - [Fix] `shallow`: prevent rerenders with PureComponents (#1786, @koba04) - [Fix] `shallow`: skip updates when nextState is `null` or `undefined` (#1785, @koba04) - [Fix] `shallow`: `setState` after `setProps` calls `componentWillReceiveProps` (#1779, @peanutenthusiast) - [Fix] `mount`/`shallow`: be stricter on the wrapper’s setState/setProps callback - [Fix] `shallow`/`mount`: improve error message when wrapping invalid elements (#1759, @jgzuke) - update deps - [Refactor] remove most uses of lodash - [meta] ensure a license and readme is present in all packages when published
Throw
TypeError('ShallowWrapper can only wrap valid elements')
orTypeError('ReactWrapper can only wrap valid elements')
whenShallowWrapper
orReactWrapper
are created wrapping an invalid element as root.