Skip to content

Commit

Permalink
throw when creating root wrappers from invalid components
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Zukewich committed Aug 16, 2018
1 parent 816f647 commit 0856e7f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ class ReactWrapper {
const options = makeOptions(passedOptions);

if (!root) {
const adapter = getAdapter(options);
if (!adapter.isValidElement(nodes)) {
throw new TypeError('ReactWrapper can only wrap valid elements')
}

privateSet(this, UNRENDERED, nodes);
const renderer = getAdapter(options).createRenderer({ mode: 'mount', ...options });
const renderer = adapter.createRenderer({ mode: 'mount', ...options });
privateSet(this, RENDERER, renderer);
renderer.render(nodes, options.context);
privateSet(this, ROOT, this);
Expand Down
8 changes: 6 additions & 2 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,17 @@ class ShallowWrapper {
validateOptions(passedOptions);
const options = makeOptions(passedOptions);
if (!root) {
const adapter = getAdapter(options);
if (!adapter.isValidElement(nodes)) {
throw new TypeError('ShallowWrapper can only wrap valid elements')
}

privateSet(this, ROOT, this);
privateSet(this, UNRENDERED, nodes);
const renderer = getAdapter(options).createRenderer({ mode: 'shallow', ...options });
const renderer = adapter.createRenderer({ mode: 'shallow', ...options });
privateSet(this, RENDERER, renderer);
this[RENDERER].render(nodes, options.context);
const { instance } = this[RENDERER].getNode();
const adapter = getAdapter(this[OPTIONS]);
const lifecycles = getAdapterLifecycles(adapter);
// Ensure to call componentDidUpdate when instance.setState is called
if (instance && lifecycles.componentDidUpdate.onSetState && !instance[SET_STATE]) {
Expand Down

0 comments on commit 0856e7f

Please sign in to comment.