Skip to content

Commit

Permalink
Fix tests; use ifReact in the 15.4 adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 6, 2018
1 parent d8fa20c commit 751b1f7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
1 change: 1 addition & 0 deletions packages/enzyme-adapter-react-15.4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"author": "Leland Richardson <leland.richardson@airbnb.com>",
"license": "MIT",
"dependencies": {
"enzyme-adapter-react-helper": "^1.2.2",
"enzyme-adapter-utils": "^1.3.0",
"lodash": "^4.17.4",
"object.assign": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import {
createMountWrapper,
propsWithKeysAndRef,
} from 'enzyme-adapter-utils';

const MINOR_VERSION = React.version.split('.')[1];
import ifReact from 'enzyme-adapter-react-helper/build/ifReact';

function compositeTypeToNodeType(type) {
switch (type) {
Expand Down Expand Up @@ -257,11 +256,11 @@ class ReactFifteenFourAdapter extends EnzymeAdapter {

invokeSetStateCallback(instance, callback) {
// React in >= 15.4, and < 16 pass undefined to a setState callback
if (MINOR_VERSION >= 4) {
callback.call(instance, undefined);
} else {
super.invokeSetStateCallback(instance, callback);
}
ifReact(
'^15.4',
() => { callback.call(instance, undefined); },
() => { super.invokeSetStateCallback(instance, callback); },
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/enzyme-test-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.5.1"
}
}
}
6 changes: 2 additions & 4 deletions packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ import { ITERATOR_SYMBOL, withSetStateAllowed, sym } from 'enzyme/build/Utils';
import './_helpers/setupAdapters';
import { createClass } from './_helpers/react-compat';
import { describeIf, itIf, itWithData, generateEmptyRenderData } from './_helpers';
import { REACT013, REACT014, REACT15, REACT150, REACT151, REACT152, REACT153, REACT16, is } from './_helpers/version';
import { REACT013, REACT014, REACT15, REACT150_4, REACT16, is } from './_helpers/version';

// The shallow renderer in react 16 does not yet support batched updates. When it does,
// we should be able to go un-skip all of the tests that are skipped with this flag.
const BATCHING = !REACT16;


// some React versions pass undefined as an argument of setState callback.
const CALLING_SETSTATE_CALLBACK_WITH_UNDEFINED =
REACT15 && !REACT150 && !REACT151 && !REACT152 && !REACT153;
const CALLING_SETSTATE_CALLBACK_WITH_UNDEFINED = REACT15 && !REACT150_4;

const getElementPropSelector = prop => x => x.props[prop];
const getWrapperPropSelector = prop => x => x.prop(prop);
Expand Down
18 changes: 12 additions & 6 deletions packages/enzyme-test-suite/test/_helpers/setupAdapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
* version of React is loaded, and configures enzyme to use the right
* corresponding adapter.
*/
const Version = require('./version');
const {
REACT013,
REACT014,
REACT15,
REACT155,
REACT16,
} = require('./version');
const Enzyme = require('enzyme');

let Adapter = null;

if (Version.REACT013) {
if (REACT013) {
Adapter = require('enzyme-adapter-react-13');
} else if (Version.REACT014) {
} else if (REACT014) {
Adapter = require('enzyme-adapter-react-14');
} else if (Version.REACT155) {
} else if (REACT155) {
Adapter = require('enzyme-adapter-react-15');
} else if (Version.REACT15) {
} else if (REACT15) {
Adapter = require('enzyme-adapter-react-15.4');
} else if (Version.REACT16) {
} else if (REACT16) {
Adapter = require('enzyme-adapter-react-16');
}

Expand Down
6 changes: 2 additions & 4 deletions packages/enzyme-test-suite/test/_helpers/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ const [major, minor] = VERSION.split('.');
export const REACT013 = VERSION.slice(0, 4) === '0.13';
export const REACT014 = VERSION.slice(0, 4) === '0.14';
export const REACT15 = major === '15';
export const REACT150 = REACT15 && minor === '0';
export const REACT151 = REACT15 && minor === '1';
export const REACT152 = REACT15 && minor === '2';
export const REACT153 = REACT15 && minor === '3';
export const REACT150_4 = REACT15 && minor < 5;
export const REACT155 = REACT15 && minor >= 5;
export const REACT16 = major === '16';

export function gt(v) { return semver.gt(VERSION, v); }
Expand Down

0 comments on commit 751b1f7

Please sign in to comment.