Skip to content

Commit 6ea171e

Browse files
committed
Fix tests; use ifReact in the 15.4 adapter
1 parent 7d8cb66 commit 6ea171e

File tree

6 files changed

+24
-22
lines changed

6 files changed

+24
-22
lines changed

packages/enzyme-adapter-react-15.4/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"author": "Leland Richardson <[email protected]>",
3535
"license": "MIT",
3636
"dependencies": {
37+
"enzyme-adapter-react-helper": "^1.2.2",
3738
"enzyme-adapter-utils": "^1.3.0",
3839
"lodash": "^4.17.4",
3940
"object.assign": "^4.1.0",

packages/enzyme-adapter-react-15.4/src/ReactFifteenFourAdapter.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ import {
1616
createMountWrapper,
1717
propsWithKeysAndRef,
1818
} from 'enzyme-adapter-utils';
19-
20-
const MINOR_VERSION = React.version.split('.')[1];
19+
import ifReact from 'enzyme-adapter-react-helper/build/ifReact';
2120

2221
function compositeTypeToNodeType(type) {
2322
switch (type) {
@@ -257,11 +256,11 @@ class ReactFifteenFourAdapter extends EnzymeAdapter {
257256

258257
invokeSetStateCallback(instance, callback) {
259258
// React in >= 15.4, and < 16 pass undefined to a setState callback
260-
if (MINOR_VERSION >= 4) {
261-
callback.call(instance, undefined);
262-
} else {
263-
super.invokeSetStateCallback(instance, callback);
264-
}
259+
ifReact(
260+
'^15.4',
261+
() => { callback.call(instance, undefined); },
262+
() => { super.invokeSetStateCallback(instance, callback); },
263+
)
265264
}
266265
}
267266

packages/enzyme-test-suite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@
4949
"eslint-plugin-jsx-a11y": "^6.0.3",
5050
"eslint-plugin-react": "^7.5.1"
5151
}
52-
}
52+
}

packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@ import { ITERATOR_SYMBOL, withSetStateAllowed, sym } from 'enzyme/build/Utils';
88
import './_helpers/setupAdapters';
99
import { createClass } from './_helpers/react-compat';
1010
import { describeIf, itIf, itWithData, generateEmptyRenderData } from './_helpers';
11-
import { REACT013, REACT014, REACT15, REACT150, REACT151, REACT152, REACT153, REACT16, is } from './_helpers/version';
11+
import { REACT013, REACT014, REACT15, REACT150_4, REACT16, is } from './_helpers/version';
1212

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

17-
1817
// some React versions pass undefined as an argument of setState callback.
19-
const CALLING_SETSTATE_CALLBACK_WITH_UNDEFINED =
20-
REACT15 && !REACT150 && !REACT151 && !REACT152 && !REACT153;
18+
const CALLING_SETSTATE_CALLBACK_WITH_UNDEFINED = REACT15 && !REACT150_4;
2119

2220
const getElementPropSelector = prop => x => x.props[prop];
2321
const getWrapperPropSelector = prop => x => x.prop(prop);

packages/enzyme-test-suite/test/_helpers/setupAdapters.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@
55
* version of React is loaded, and configures enzyme to use the right
66
* corresponding adapter.
77
*/
8-
const Version = require('./version');
8+
const {
9+
REACT013,
10+
REACT014,
11+
REACT15,
12+
REACT155,
13+
REACT16,
14+
} = require('./version');
915
const Enzyme = require('enzyme');
1016

1117
let Adapter = null;
1218

13-
if (Version.REACT013) {
19+
if (REACT013) {
1420
Adapter = require('enzyme-adapter-react-13');
15-
} else if (Version.REACT014) {
21+
} else if (REACT014) {
1622
Adapter = require('enzyme-adapter-react-14');
17-
} else if (Version.REACT155) {
23+
} else if (REACT155) {
1824
Adapter = require('enzyme-adapter-react-15');
19-
} else if (Version.REACT15) {
25+
} else if (REACT15) {
2026
Adapter = require('enzyme-adapter-react-15.4');
21-
} else if (Version.REACT16) {
27+
} else if (REACT16) {
2228
Adapter = require('enzyme-adapter-react-16');
2329
}
2430

packages/enzyme-test-suite/test/_helpers/version.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ const [major, minor] = VERSION.split('.');
88
export const REACT013 = VERSION.slice(0, 4) === '0.13';
99
export const REACT014 = VERSION.slice(0, 4) === '0.14';
1010
export const REACT15 = major === '15';
11-
export const REACT150 = REACT15 && minor === '0';
12-
export const REACT151 = REACT15 && minor === '1';
13-
export const REACT152 = REACT15 && minor === '2';
14-
export const REACT153 = REACT15 && minor === '3';
11+
export const REACT150_4 = REACT15 && minor < 5;
12+
export const REACT155 = REACT15 && minor >= 5;
1513
export const REACT16 = major === '16';
1614

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

0 commit comments

Comments
 (0)