Skip to content

Commit 1aa8dd6

Browse files
committed
optimise check version logic
1 parent 6302071 commit 1aa8dd6

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"husky": "^0.11.9",
4040
"jsdom": "^9.8.3",
4141
"mocha": "^3.1.2",
42+
"proxyquire": "^1.7.10",
4243
"react": "^15.4.0-rc.4",
4344
"react-addons-shallow-compare": "^15.4.0-rc.4",
4445
"react-addons-test-utils": "^15.4.0-rc.4",

src/extendReactClass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import _ from 'lodash';
44
import hoistNonReactStatics from 'hoist-non-react-statics';
55
import linkClass from './linkClass';
6-
import renderNothing from './renderNothing';
6+
import nothing from './renderNothing';
77

88
/**
99
* @param {ReactClass} Component
@@ -49,7 +49,7 @@ export default (Component: Object, defaultStyles: Object, options: Object) => {
4949
return linkClass(renderResult, styles, options);
5050
}
5151

52-
return renderNothing();
52+
return nothing;
5353
}
5454
};
5555

src/renderNothing.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react';
22

3-
export default function () {
4-
const major = React.version.split('.')[0];
3+
const major = React.version.split('.')[0];
4+
const nothing = parseInt(major, 10) < 15 ? React.createElement('noscript') : null;
55

6-
return parseInt(major, 10) < 15 ? React.createElement('noscript') : null;
7-
}
6+
export default nothing;

src/wrapStatelessFunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import _ from 'lodash';
44
import linkClass from './linkClass';
5-
import renderNothing from './renderNothing';
5+
import nothing from './renderNothing';
66

77
/**
88
* @see https://facebook.github.io/react/blog/2015/09/10/react-v0.14-rc1.html#stateless-function-components
@@ -39,7 +39,7 @@ export default (Component: Function, defaultStyles: Object, options: Object): Fu
3939
return linkClass(renderResult, styles, options);
4040
}
4141

42-
return renderNothing();
42+
return nothing;
4343
};
4444

4545
_.assign(WrappedComponent, Component);

tests/renderNothing.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
import {
44
expect
55
} from 'chai';
6-
import React from 'react';
7-
import renderNothing from '../src/renderNothing';
8-
9-
const version = React.version;
6+
import proxyquire from 'proxyquire';
107

118
describe('renderNothing', () => {
129
context('renderNothing should return different node types for various React versions', () => {
13-
it('should return noscript tag for React v14.0.0', () => {
14-
React.version = '14.0.0';
15-
expect(renderNothing().type).to.equal('noscript');
16-
React.version = version;
10+
it('should return null for React v15.0.0 or later', () => {
11+
const renderNothing = proxyquire('../src/renderNothing', {react: {version: '15.0.0'}});
12+
13+
expect(renderNothing).to.equal(null);
1714
});
1815

19-
it('should return null for current version', () => {
20-
expect(renderNothing()).to.equal(null);
16+
it('should return noscript tag for React v14.0.0 or earlier', () => {
17+
const renderNothing = proxyquire('../src/renderNothing', {react: {version: '14.0.0'}});
18+
19+
expect(renderNothing.type).to.equal('noscript');
2120
});
2221
});
2322
});

0 commit comments

Comments
 (0)