Skip to content

Commit

Permalink
[Fix] shallow/mount: state()/setState(): error on Portals
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 24, 2018
1 parent 678fa9d commit 4e88f1b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class ReactWrapper {
if (this[ROOT] !== this) {
throw new Error('ReactWrapper::setState() can only be called on the root');
}
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') {
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') {
throw new Error('ReactWrapper::setState() can only be called on class components');
}
if (arguments.length > 1 && typeof callback !== 'function') {
Expand Down Expand Up @@ -637,7 +637,7 @@ class ReactWrapper {
if (this[ROOT] !== this) {
throw new Error('ReactWrapper::state() can only be called on the root');
}
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') {
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') {
throw new Error('ReactWrapper::state() can only be called on class components');
}
const _state = this.single('state', () => this.instance().state);
Expand Down
4 changes: 2 additions & 2 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ class ShallowWrapper {
if (this[ROOT] !== this) {
throw new Error('ShallowWrapper::setState() can only be called on the root');
}
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') {
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') {
throw new Error('ShallowWrapper::setState() can only be called on class components');
}
if (arguments.length > 1 && typeof callback !== 'function') {
Expand Down Expand Up @@ -864,7 +864,7 @@ class ShallowWrapper {
if (this[ROOT] !== this) {
throw new Error('ShallowWrapper::state() can only be called on the root');
}
if (this.instance() === null || this[RENDERER].getNode().nodeType === 'function') {
if (this.instance() === null || this[RENDERER].getNode().nodeType !== 'class') {
throw new Error('ShallowWrapper::state() can only be called on class components');
}
const _state = this.single('state', () => this.instance().state);
Expand Down

0 comments on commit 4e88f1b

Please sign in to comment.