Skip to content

Commit

Permalink
stub instance.setState when the component is mounting
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Aug 9, 2018
1 parent 3b3ab38 commit f12be61
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,13 @@ class ShallowWrapper {
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]) {
privateSet(instance, SET_STATE, instance.setState);
instance.setState = (...args) => this.setState(...args);
}
if (
!options.disableLifecycleMethods
&& instance
Expand Down Expand Up @@ -264,16 +271,7 @@ class ShallowWrapper {
if (this[ROOT] !== this) {
throw new Error('ShallowWrapper::instance() can only be called on the root');
}
const adapter = getAdapter(this[OPTIONS]);
const lifecycles = getAdapterLifecycles(adapter);

const { instance } = this[RENDERER].getNode();
// Ensure to call componentDidUpdate when instance.setState is called
if (instance && lifecycles.componentDidUpdate.onSetState && !instance[SET_STATE]) {
privateSet(instance, SET_STATE, instance.setState);
instance.setState = (...args) => this.setState(...args);
}
return instance;
return this[RENDERER].getNode().instance;
}

/**
Expand Down

0 comments on commit f12be61

Please sign in to comment.