Skip to content

Commit

Permalink
update to instance-level options
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandrichardson committed Sep 26, 2017
1 parent 88d9c76 commit a08df67
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
8 changes: 7 additions & 1 deletion packages/enzyme-adapter-react-13/src/ReactThirteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ function instanceToTree(inst) {
}

class ReactThirteenAdapter extends EnzymeAdapter {
constructor() {
super();
this.options = {
...this.options,
supportPrevContextArgumentOfComponentDidUpdate: true,
};
}
createMountRenderer(options) {
assertDomAvailable('mount');
const domNode = options.attachTo || global.document.createElement('div');
Expand Down Expand Up @@ -144,7 +151,6 @@ class ReactThirteenAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
supportPrevContextArgumentOfComponentDidUpdate: true,
render(el, context) {
cachedNode = el;
/* eslint consistent-return: 0 */
Expand Down
8 changes: 7 additions & 1 deletion packages/enzyme-adapter-react-14/src/ReactFourteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ function instanceToTree(inst) {
}

class ReactFifteenAdapter extends EnzymeAdapter {
constructor() {
super();
this.options = {
...this.options,
supportPrevContextArgumentOfComponentDidUpdate: true,
};
}
createMountRenderer(options) {
assertDomAvailable('mount');
const domNode = options.attachTo || global.document.createElement('div');
Expand Down Expand Up @@ -116,7 +123,6 @@ class ReactFifteenAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
supportPrevContextArgumentOfComponentDidUpdate: true,
render(el, context) {
cachedNode = el;
/* eslint consistent-return: 0 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ function instanceToTree(inst) {
}

class ReactFifteenFourAdapter extends EnzymeAdapter {
constructor() {
super();
this.options = {
...this.options,
supportPrevContextArgumentOfComponentDidUpdate: true,
};
}
createMountRenderer(options) {
assertDomAvailable('mount');
const domNode = options.attachTo || global.document.createElement('div');
Expand Down Expand Up @@ -146,7 +153,6 @@ class ReactFifteenFourAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
supportPrevContextArgumentOfComponentDidUpdate: true,
render(el, context) {
cachedNode = el;
/* eslint consistent-return: 0 */
Expand Down
8 changes: 7 additions & 1 deletion packages/enzyme-adapter-react-15/src/ReactFifteenAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ function instanceToTree(inst) {
}

class ReactFifteenAdapter extends EnzymeAdapter {
constructor() {
super();
this.options = {
...this.options,
supportPrevContextArgumentOfComponentDidUpdate: true,
};
}
createMountRenderer(options) {
assertDomAvailable('mount');
const domNode = options.attachTo || global.document.createElement('div');
Expand Down Expand Up @@ -146,7 +153,6 @@ class ReactFifteenAdapter extends EnzymeAdapter {
let isDOM = false;
let cachedNode = null;
return {
supportPrevContextArgumentOfComponentDidUpdate: true,
render(el, context) {
cachedNode = el;
/* eslint consistent-return: 0 */
Expand Down
3 changes: 1 addition & 2 deletions packages/enzyme-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,4 @@
"react": "^15.5.0",
"react-dom": "^15.5.0"
}
}

}
8 changes: 6 additions & 2 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class ShallowWrapper {
instance &&
typeof instance.componentDidUpdate === 'function'
) {
if (this[RENDERER].supportPrevContextArgumentOfComponentDidUpdate) {
if (adapter.options.supportPrevContextArgumentOfComponentDidUpdate) {
instance.componentDidUpdate(prevProps, state, prevContext);
} else {
instance.componentDidUpdate(prevProps, state);
Expand Down Expand Up @@ -405,7 +405,11 @@ class ShallowWrapper {
instance &&
typeof instance.componentDidUpdate === 'function'
) {
instance.componentDidUpdate(prevProps, prevState, prevContext);
if (adapter.options.supportPrevContextArgumentOfComponentDidUpdate) {
instance.componentDidUpdate(prevProps, prevState, prevContext);
} else {
instance.componentDidUpdate(prevProps, prevState);
}
}
this.update();
});
Expand Down

0 comments on commit a08df67

Please sign in to comment.