Skip to content

Commit 9f1ccb8

Browse files
committed
Merge branch 'master' of github.com:gajus/react-css-modules
2 parents 480bb29 + a9c8de2 commit 9f1ccb8

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

src/extendReactClass.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* eslint-disable react/prop-types */
22

3-
import React from 'react';
43
import _ from 'lodash';
4+
import React from 'react';
55
import hoistNonReactStatics from 'hoist-non-react-statics';
66
import linkClass from './linkClass';
7+
import renderNothing from './renderNothing';
78

89
/**
910
* @param {ReactClass} Component
@@ -49,9 +50,9 @@ export default (Component: Object, defaultStyles: Object, options: Object) => {
4950
return linkClass(renderResult, styles, options);
5051
}
5152

52-
return React.createElement('noscript');
53+
return renderNothing(React.version);
5354
}
54-
};
55+
};
5556

5657
return hoistNonReactStatics(WrappedComponent, Component);
5758
};

src/renderNothing.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
export default function (version) {
4+
const major = version.split('.')[0];
5+
6+
return parseInt(major, 10) < 15 ? React.createElement('noscript') : null;
7+
}

src/wrapStatelessFunction.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import _ from 'lodash';
44
import React from 'react';
55
import linkClass from './linkClass';
6+
import renderNothing from './renderNothing';
67

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

42-
return React.createElement('noscript');
43+
return renderNothing(React.version);
4344
};
4445

4546
_.assign(WrappedComponent, Component);

tests/extendReactClass.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('extendReactClass', () => {
128128
});
129129
});
130130
context('rendering Component that returns null', () => {
131-
it('generates <noscript> element', () => {
131+
it('generates null', () => {
132132
let Component;
133133

134134
const shallowRenderer = TestUtils.createRenderer();
@@ -145,7 +145,7 @@ describe('extendReactClass', () => {
145145

146146
const component = shallowRenderer.getRenderOutput();
147147

148-
expect(component.type).to.equal('noscript');
148+
expect(component).to.equal(null);
149149
});
150150
});
151151
context('target component have static properties', () => {

tests/renderNothing.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {
2+
expect
3+
} from 'chai';
4+
import renderNothing from '../src/renderNothing';
5+
6+
describe('renderNothing', () => {
7+
context('renderNothing should return different node types for various React versions', () => {
8+
it('should return noscript tag for React v14 or lower', () => {
9+
expect(renderNothing('14.0.0').type).to.equal('noscript');
10+
});
11+
12+
it('should return null for React v15 or higher', () => {
13+
expect(renderNothing('15.0.0')).to.equal(null);
14+
});
15+
});
16+
});

tests/wrapStatelessFunction.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ describe('wrapStatelessFunction', () => {
7575
});
7676
});
7777
context('rendering Component that returns null', () => {
78-
it('generates <noscript> element', () => {
78+
it('generates null', () => {
7979
const shallowRenderer = TestUtils.createRenderer();
8080

8181
const Component = wrapStatelessFunction(() => {
@@ -86,7 +86,7 @@ describe('wrapStatelessFunction', () => {
8686

8787
const component = shallowRenderer.getRenderOutput();
8888

89-
expect(component.type).to.equal('noscript');
89+
expect(component).to.equal(null);
9090
});
9191
});
9292
});

0 commit comments

Comments
 (0)