Skip to content

Commit

Permalink
optimise check version logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sdoomz committed Nov 24, 2016
1 parent 6302071 commit 1aa8dd6
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"husky": "^0.11.9",
"jsdom": "^9.8.3",
"mocha": "^3.1.2",
"proxyquire": "^1.7.10",
"react": "^15.4.0-rc.4",
"react-addons-shallow-compare": "^15.4.0-rc.4",
"react-addons-test-utils": "^15.4.0-rc.4",
Expand Down
4 changes: 2 additions & 2 deletions src/extendReactClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import _ from 'lodash';
import hoistNonReactStatics from 'hoist-non-react-statics';
import linkClass from './linkClass';
import renderNothing from './renderNothing';
import nothing from './renderNothing';

/**
* @param {ReactClass} Component
Expand Down Expand Up @@ -49,7 +49,7 @@ export default (Component: Object, defaultStyles: Object, options: Object) => {
return linkClass(renderResult, styles, options);
}

return renderNothing();
return nothing;
}
};

Expand Down
7 changes: 3 additions & 4 deletions src/renderNothing.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';

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

return parseInt(major, 10) < 15 ? React.createElement('noscript') : null;
}
export default nothing;
4 changes: 2 additions & 2 deletions src/wrapStatelessFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import _ from 'lodash';
import linkClass from './linkClass';
import renderNothing from './renderNothing';
import nothing from './renderNothing';

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

return renderNothing();
return nothing;
};

_.assign(WrappedComponent, Component);
Expand Down
19 changes: 9 additions & 10 deletions tests/renderNothing.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
import {
expect
} from 'chai';
import React from 'react';
import renderNothing from '../src/renderNothing';

const version = React.version;
import proxyquire from 'proxyquire';

describe('renderNothing', () => {
context('renderNothing should return different node types for various React versions', () => {
it('should return noscript tag for React v14.0.0', () => {
React.version = '14.0.0';
expect(renderNothing().type).to.equal('noscript');
React.version = version;
it('should return null for React v15.0.0 or later', () => {
const renderNothing = proxyquire('../src/renderNothing', {react: {version: '15.0.0'}});

expect(renderNothing).to.equal(null);
});

it('should return null for current version', () => {
expect(renderNothing()).to.equal(null);
it('should return noscript tag for React v14.0.0 or earlier', () => {
const renderNothing = proxyquire('../src/renderNothing', {react: {version: '14.0.0'}});

expect(renderNothing.type).to.equal('noscript');
});
});
});

0 comments on commit 1aa8dd6

Please sign in to comment.