styled-components 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/CODE_OF_CONDUCT.md +1 -1
  3. package/README.md +12 -67
  4. package/dist/styled-components.es.js +273 -110
  5. package/dist/styled-components.js +325 -119
  6. package/dist/styled-components.min.js +2 -2
  7. package/lib/hoc/withTheme.js +13 -7
  8. package/lib/models/BrowserStyleSheet.js +11 -0
  9. package/lib/models/ComponentStyle.js +45 -2
  10. package/lib/models/InlineStyle.js +1 -1
  11. package/lib/models/ServerStyleSheet.js +33 -17
  12. package/lib/models/StyleSheet.js +9 -0
  13. package/lib/models/StyledComponent.js +82 -38
  14. package/lib/models/StyledNativeComponent.js +31 -15
  15. package/lib/models/ThemeProvider.js +44 -12
  16. package/lib/native/index.js +1 -1
  17. package/lib/test/utils.js +5 -2
  18. package/lib/utils/create-broadcast.js +34 -24
  19. package/lib/utils/domElements.js +1 -1
  20. package/lib/utils/flatten.js +4 -1
  21. package/lib/utils/generateAlphabeticName.js +1 -1
  22. package/lib/utils/nonce.js +10 -0
  23. package/lib/utils/once.js +17 -0
  24. package/package.json +10 -10
  25. package/src/hoc/withTheme.js +14 -7
  26. package/src/models/BrowserStyleSheet.js +8 -0
  27. package/src/models/ComponentStyle.js +42 -2
  28. package/src/models/InlineStyle.js +1 -1
  29. package/src/models/ServerStyleSheet.js +27 -12
  30. package/src/models/StyleSheet.js +9 -0
  31. package/src/models/StyledComponent.js +81 -26
  32. package/src/models/StyledNativeComponent.js +30 -10
  33. package/src/models/ThemeProvider.js +38 -9
  34. package/src/models/test/ThemeProvider.test.js +7 -8
  35. package/src/native/index.js +1 -1
  36. package/src/native/test/native.test.js +14 -0
  37. package/src/test/__snapshots__/ssr.test.js.snap +147 -0
  38. package/src/test/expanded-api.test.js +24 -0
  39. package/src/test/props.test.js +14 -3
  40. package/src/test/ssr.test.js +90 -123
  41. package/src/test/styles.test.js +52 -0
  42. package/src/test/utils.js +5 -2
  43. package/src/utils/create-broadcast.js +31 -17
  44. package/src/utils/domElements.js +1 -0
  45. package/src/utils/flatten.js +16 -6
  46. package/src/utils/generateAlphabeticName.js +1 -1
  47. package/src/utils/nonce.js +6 -0
  48. package/src/utils/once.js +12 -0
  49. package/typings/styled-components.d.ts +15 -21
  50. package/typings/tests/issue1068.tsx +226 -0
  51. package/typings/tests/main-test.tsx +1 -1
  52. package/typings/tests/string-tags-test.tsx +62 -0
  53. package/typings/tests/themed-tests/issue1068.tsx +226 -0
  54. package/typings/tests/themed-tests/mytheme-styled-components.tsx +1 -1
  55. package/typings/tests/themed-tests/with-theme-test.tsx +2 -1
  56. package/typings/tests/with-theme-test.tsx +17 -0
  57. package/lib/constructors/test/injectGlobal.test.js +0 -63
  58. package/lib/constructors/test/keyframes.test.js +0 -48
  59. package/lib/constructors/test/styled.test.js +0 -19
  60. package/lib/models/AbstractStyledComponent.js +0 -43
  61. package/lib/models/test/ThemeProvider.test.js +0 -200
  62. package/lib/native/test/native.test.js +0 -290
  63. package/lib/no-parser/test/basic.test.js +0 -46
  64. package/lib/no-parser/test/flatten.test.js +0 -125
  65. package/lib/no-parser/test/keyframes.test.js +0 -45
  66. package/lib/primitives/test/primitives.test.js +0 -289
  67. package/lib/test/attrs.test.js +0 -158
  68. package/lib/test/basic.test.js +0 -267
  69. package/lib/test/css.test.js +0 -43
  70. package/lib/test/expanded-api.test.js +0 -90
  71. package/lib/test/extending.test.js +0 -198
  72. package/lib/test/overriding.test.js +0 -35
  73. package/lib/test/props.test.js +0 -38
  74. package/lib/test/rehydration.test.js +0 -306
  75. package/lib/test/ssr.test.js +0 -187
  76. package/lib/test/styles.test.js +0 -146
  77. package/lib/test/theme.test.js +0 -497
  78. package/lib/test/warnTooManyClasses.test.js +0 -71
  79. package/lib/utils/test/extractCompsFromCSS.test.js +0 -46
  80. package/lib/utils/test/flatten.test.js +0 -109
  81. package/lib/utils/test/generateAlphabeticName.test.js +0 -14
  82. package/lib/utils/test/interleave.test.js +0 -22
  83. package/lib/utils/test/validAttr.test.js +0 -560
  84. package/src/models/AbstractStyledComponent.js +0 -21
  85. package/typings/tags.d.ts +0 -137
@@ -1,19 +0,0 @@
1
- 'use strict';
2
-
3
- var _index = require('../../index');
4
-
5
- var _index2 = _interopRequireDefault(_index);
6
-
7
- var _domElements = require('../../utils/domElements');
8
-
9
- var _domElements2 = _interopRequireDefault(_domElements);
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- describe('styled', function () {
14
- it('should have all valid HTML5 elements defined as properties', function () {
15
- _domElements2.default.forEach(function (domElement) {
16
- expect(_index2.default[domElement]).toBeTruthy();
17
- });
18
- });
19
- });
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- exports.__esModule = true;
4
-
5
- var _AbstractStyledCompon;
6
-
7
- var _react = require('react');
8
-
9
- var _propTypes = require('prop-types');
10
-
11
- var _propTypes2 = _interopRequireDefault(_propTypes);
12
-
13
- var _ThemeProvider = require('./ThemeProvider');
14
-
15
- var _StyleSheet = require('./StyleSheet');
16
-
17
- var _StyleSheet2 = _interopRequireDefault(_StyleSheet);
18
-
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
-
21
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
-
23
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
24
-
25
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
26
-
27
- var AbstractStyledComponent = function (_Component) {
28
- _inherits(AbstractStyledComponent, _Component);
29
-
30
- function AbstractStyledComponent() {
31
- _classCallCheck(this, AbstractStyledComponent);
32
-
33
- return _possibleConstructorReturn(this, _Component.apply(this, arguments));
34
- }
35
-
36
- return AbstractStyledComponent;
37
- }(_react.Component);
38
-
39
- exports.default = AbstractStyledComponent;
40
-
41
-
42
- AbstractStyledComponent.contextTypes = (_AbstractStyledCompon = {}, _AbstractStyledCompon[_ThemeProvider.CHANNEL] = _propTypes2.default.func, _AbstractStyledCompon[_StyleSheet.CONTEXT_KEY] = _propTypes2.default.instanceOf(_StyleSheet2.default), _AbstractStyledCompon);
43
- module.exports = exports['default'];
@@ -1,200 +0,0 @@
1
- 'use strict';
2
-
3
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
4
-
5
- var _react = require('react');
6
-
7
- var _react2 = _interopRequireDefault(_react);
8
-
9
- var _propTypes = require('prop-types');
10
-
11
- var _propTypes2 = _interopRequireDefault(_propTypes);
12
-
13
- var _enzyme = require('enzyme');
14
-
15
- var _ThemeProvider = require('../ThemeProvider');
16
-
17
- var _ThemeProvider2 = _interopRequireDefault(_ThemeProvider);
18
-
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
-
21
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
22
-
23
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
24
-
25
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
26
- /* eslint-disable react/no-multi-comp */
27
-
28
-
29
- describe('ThemeProvider', function () {
30
- it('should not throw an error when no children are passed', function () {
31
- var result = (0, _enzyme.shallow)(_react2.default.createElement(_ThemeProvider2.default, { theme: {} }));
32
- expect(result.html()).toEqual(null);
33
- });
34
-
35
- it('should accept a theme prop that\'s a plain object', function () {
36
- (0, _enzyme.shallow)(_react2.default.createElement(_ThemeProvider2.default, { theme: { main: 'black' } }));
37
- });
38
-
39
- it('should render its child', function () {
40
- var child = _react2.default.createElement(
41
- 'p',
42
- null,
43
- 'Child!'
44
- );
45
- var renderedComp = (0, _enzyme.shallow)(_react2.default.createElement(
46
- _ThemeProvider2.default,
47
- { theme: { main: 'black' } },
48
- child
49
- ));
50
- expect(renderedComp.contains(child)).toEqual(true);
51
- });
52
-
53
- it('should merge its theme with an outer theme', function (done) {
54
- var _Child$contextTypes;
55
-
56
- var outerTheme = { main: 'black' };
57
- var innerTheme = { secondary: 'black' };
58
- // Setup Child
59
-
60
- var Child = function (_React$Component) {
61
- _inherits(Child, _React$Component);
62
-
63
- function Child() {
64
- _classCallCheck(this, Child);
65
-
66
- return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
67
- }
68
-
69
- Child.prototype.componentWillMount = function componentWillMount() {
70
- this.context[_ThemeProvider.CHANNEL](function (theme) {
71
- expect(theme).toEqual(_extends({}, outerTheme, innerTheme));
72
- done();
73
- });
74
- };
75
-
76
- Child.prototype.render = function render() {
77
- return null;
78
- };
79
-
80
- return Child;
81
- }(_react2.default.Component);
82
-
83
- Child.contextTypes = (_Child$contextTypes = {}, _Child$contextTypes[_ThemeProvider.CHANNEL] = _propTypes2.default.object, _Child$contextTypes);
84
-
85
- (0, _enzyme.render)(_react2.default.createElement(
86
- _ThemeProvider2.default,
87
- { theme: outerTheme },
88
- _react2.default.createElement(
89
- _ThemeProvider2.default,
90
- { theme: innerTheme },
91
- _react2.default.createElement(Child, null)
92
- )
93
- ));
94
- });
95
-
96
- it('should merge its theme with multiple outer themes', function (done) {
97
- var _Child$contextTypes2;
98
-
99
- var outerestTheme = { main: 'black' };
100
- var outerTheme = { main: 'blue' };
101
- var innerTheme = { secondary: 'black' };
102
- // Setup Child
103
-
104
- var Child = function (_React$Component2) {
105
- _inherits(Child, _React$Component2);
106
-
107
- function Child() {
108
- _classCallCheck(this, Child);
109
-
110
- return _possibleConstructorReturn(this, _React$Component2.apply(this, arguments));
111
- }
112
-
113
- Child.prototype.componentWillMount = function componentWillMount() {
114
- this.context[_ThemeProvider.CHANNEL](function (theme) {
115
- expect(theme).toEqual(_extends({}, outerestTheme, outerTheme, innerTheme));
116
- done();
117
- });
118
- };
119
-
120
- Child.prototype.render = function render() {
121
- return null;
122
- };
123
-
124
- return Child;
125
- }(_react2.default.Component);
126
-
127
- Child.contextTypes = (_Child$contextTypes2 = {}, _Child$contextTypes2[_ThemeProvider.CHANNEL] = _propTypes2.default.object, _Child$contextTypes2);
128
-
129
- (0, _enzyme.render)(_react2.default.createElement(
130
- _ThemeProvider2.default,
131
- { theme: outerestTheme },
132
- _react2.default.createElement(
133
- _ThemeProvider2.default,
134
- { theme: outerTheme },
135
- _react2.default.createElement(
136
- _ThemeProvider2.default,
137
- { theme: innerTheme },
138
- _react2.default.createElement(Child, null)
139
- )
140
- )
141
- ));
142
- });
143
-
144
- it('should be able to render two independent themes', function (done) {
145
- var _Child$contextTypes3;
146
-
147
- var themes = {
148
- one: { main: 'black', secondary: 'red' },
149
- two: { main: 'blue', other: 'green' }
150
- };
151
- var childRendered = 0;
152
- // Setup Child
153
-
154
- var Child = function (_React$Component3) {
155
- _inherits(Child, _React$Component3);
156
-
157
- function Child() {
158
- _classCallCheck(this, Child);
159
-
160
- return _possibleConstructorReturn(this, _React$Component3.apply(this, arguments));
161
- }
162
-
163
- Child.prototype.componentWillMount = function componentWillMount() {
164
- var _this4 = this;
165
-
166
- this.context[_ThemeProvider.CHANNEL](function (theme) {
167
- // eslint-disable-next-line react/prop-types
168
- expect(theme).toEqual(themes[_this4.props.shouldHaveTheme]);
169
- childRendered++; // eslint-disable-line no-plusplus
170
- if (childRendered === Object.keys(themes).length) {
171
- done();
172
- }
173
- });
174
- };
175
-
176
- Child.prototype.render = function render() {
177
- return null;
178
- };
179
-
180
- return Child;
181
- }(_react2.default.Component);
182
-
183
- Child.contextTypes = (_Child$contextTypes3 = {}, _Child$contextTypes3[_ThemeProvider.CHANNEL] = _propTypes2.default.object, _Child$contextTypes3);
184
-
185
- (0, _enzyme.render)(_react2.default.createElement(
186
- 'div',
187
- null,
188
- _react2.default.createElement(
189
- _ThemeProvider2.default,
190
- { theme: themes.one },
191
- _react2.default.createElement(Child, { shouldHaveTheme: 'one' })
192
- ),
193
- _react2.default.createElement(
194
- _ThemeProvider2.default,
195
- { theme: themes.two },
196
- _react2.default.createElement(Child, { shouldHaveTheme: 'two' })
197
- )
198
- ));
199
- });
200
- });
@@ -1,290 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose([''], ['']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['\n padding-top: 10;\n '], ['\n padding-top: 10;\n ']),
5
- _templateObject3 = _taggedTemplateLiteralLoose(['opacity: 0.9;'], ['opacity: 0.9;']),
6
- _templateObject4 = _taggedTemplateLiteralLoose(['padding: 10px;'], ['padding: 10px;']),
7
- _templateObject5 = _taggedTemplateLiteralLoose(['background-color: red;'], ['background-color: red;']),
8
- _templateObject6 = _taggedTemplateLiteralLoose(['borderWidth: 10;'], ['borderWidth: 10;']);
9
-
10
- require('react-native');
11
-
12
- var _react = require('react');
13
-
14
- var _react2 = _interopRequireDefault(_react);
15
-
16
- var _index = require('../index');
17
-
18
- var _index2 = _interopRequireDefault(_index);
19
-
20
- var _enzyme = require('enzyme');
21
-
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
25
-
26
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
27
-
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
29
-
30
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
31
-
32
- // NOTE: These tests are like the ones for Web but a "light-version" of them
33
- // This is mostly due to the similar logic
34
-
35
- describe('native', function () {
36
- it('should not throw an error when called', function () {
37
- _index2.default.View(_templateObject);
38
- });
39
-
40
- it('should generate inline styles', function () {
41
- var Comp = _index2.default.View(_templateObject);
42
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
43
- var view = wrapper.find('View').first();
44
-
45
- expect(view.prop('style')).toEqual([{}, undefined]);
46
- });
47
-
48
- it('should combine inline styles and the style prop', function () {
49
- var Comp = _index2.default.View(_templateObject2);
50
-
51
- var style = { opacity: 0.9 };
52
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, { style: style }));
53
- var view = wrapper.find('View').first();
54
-
55
- expect(view.prop('style')).toEqual([{ paddingTop: 10 }, style]);
56
- });
57
-
58
- describe('extending', function () {
59
- it('should combine styles of extending components', function () {
60
- var Parent = _index2.default.View(_templateObject3);
61
- var Child = Parent.extend(_templateObject4);
62
-
63
- var parent = (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
64
- var child = (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
65
-
66
- expect(parent.find('View').prop('style')).toEqual([{ opacity: 0.9 }, undefined]);
67
-
68
- expect(child.find('View').prop('style')).toEqual([{
69
- opacity: 0.9,
70
- paddingTop: 10,
71
- paddingRight: 10,
72
- paddingBottom: 10,
73
- paddingLeft: 10
74
- }, undefined]);
75
- });
76
-
77
- it('should combine styles of extending components in >= 3 inheritances', function () {
78
- var GrandGrandParent = _index2.default.View(_templateObject5);
79
- var GrandParent = GrandGrandParent.extend(_templateObject6);
80
- var Parent = GrandParent.extend(_templateObject3);
81
- var Child = Parent.extend(_templateObject4);
82
-
83
- var grandGrandParent = (0, _enzyme.shallow)(_react2.default.createElement(GrandGrandParent, null));
84
- var grandParent = (0, _enzyme.shallow)(_react2.default.createElement(GrandParent, null));
85
- var parent = (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
86
- var child = (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
87
-
88
- expect(grandGrandParent.find('View').prop('style')).toEqual([{
89
- backgroundColor: 'red'
90
- }, undefined]);
91
-
92
- expect(grandParent.find('View').prop('style')).toEqual([{
93
- backgroundColor: 'red',
94
- borderWidth: 10
95
- }, undefined]);
96
-
97
- expect(parent.find('View').prop('style')).toEqual([{
98
- backgroundColor: 'red',
99
- borderWidth: 10,
100
- opacity: 0.9
101
- }, undefined]);
102
-
103
- expect(child.find('View').prop('style')).toEqual([{
104
- backgroundColor: 'red',
105
- borderWidth: 10,
106
- opacity: 0.9,
107
- paddingTop: 10,
108
- paddingRight: 10,
109
- paddingBottom: 10,
110
- paddingLeft: 10
111
- }, undefined]);
112
- });
113
- });
114
-
115
- describe('attrs', function () {
116
- it('works fine with an empty object', function () {
117
- var Comp = _index2.default.View.attrs({})(_templateObject);
118
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
119
- var view = wrapper.find('View').first();
120
-
121
- expect(view.props()).toEqual({
122
- style: [{}, undefined]
123
- });
124
- });
125
-
126
- it('passes simple props on', function () {
127
- var Comp = _index2.default.View.attrs({
128
- test: true
129
- })(_templateObject);
130
-
131
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
132
- var view = wrapper.find('View').first();
133
-
134
- expect(view.props()).toEqual({
135
- style: [{}, undefined],
136
- test: true
137
- });
138
- });
139
-
140
- it('calls an attr-function with context', function () {
141
- var Comp = _index2.default.View.attrs({
142
- copy: function copy(props) {
143
- return props.test;
144
- }
145
- })(_templateObject);
146
-
147
- var test = 'Put that cookie down!';
148
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, { test: test }));
149
- var view = wrapper.find('View').first();
150
-
151
- expect(view.props()).toEqual({
152
- style: [{}, undefined],
153
- copy: test,
154
- test: test
155
- });
156
- });
157
-
158
- it('merges multiple calls', function () {
159
- var Comp = _index2.default.View.attrs({
160
- first: 'first',
161
- test: '_'
162
- }).attrs({
163
- second: 'second',
164
- test: 'test'
165
- })(_templateObject);
166
-
167
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
168
- var view = wrapper.find('View').first();
169
-
170
- expect(view.props()).toEqual({
171
- style: [{}, undefined],
172
- first: 'first',
173
- second: 'second',
174
- test: 'test'
175
- });
176
- });
177
-
178
- it('merges attrs when inheriting SC', function () {
179
- var Parent = _index2.default.View.attrs({
180
- first: 'first'
181
- })(_templateObject);
182
-
183
- var Child = Parent.extend.attrs({
184
- second: 'second'
185
- })(_templateObject);
186
-
187
- var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
188
- var view = wrapper.find('View').first();
189
-
190
- expect(view.props()).toEqual({
191
- style: [{}, undefined],
192
- first: 'first',
193
- second: 'second'
194
- });
195
- });
196
- });
197
-
198
- describe('expanded API', function () {
199
- it('should attach a displayName', function () {
200
- var Comp = _index2.default.View(_templateObject);
201
- expect(Comp.displayName).toBe('Styled(View)');
202
-
203
- var CompTwo = _index2.default.View.withConfig({ displayName: 'Test' })(_templateObject);
204
- expect(CompTwo.displayName).toBe('Test');
205
- });
206
-
207
- it('should allow multiple calls to be chained', function () {
208
- var Comp = _index2.default.View.withConfig({ displayName: 'Test1' }).withConfig({ displayName: 'Test2' })(_templateObject);
209
-
210
- expect(Comp.displayName).toBe('Test2');
211
- });
212
- });
213
-
214
- describe('innerRef', function () {
215
- it('should pass the ref to the component', function () {
216
- var Comp = _index2.default.View(_templateObject);
217
- var ref = jest.fn();
218
-
219
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(Comp, { innerRef: ref }));
220
- var view = wrapper.find('View').first();
221
- var comp = wrapper.find(Comp).first();
222
-
223
- // $FlowFixMe
224
- expect(ref).toHaveBeenCalledWith(view.node);
225
- expect(view.prop('innerRef')).toBeFalsy();
226
- expect(comp.node.root).toBeTruthy();
227
- });
228
-
229
- var InnerComponent = function (_React$Component) {
230
- _inherits(InnerComponent, _React$Component);
231
-
232
- function InnerComponent() {
233
- _classCallCheck(this, InnerComponent);
234
-
235
- return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
236
- }
237
-
238
- InnerComponent.prototype.render = function render() {
239
- return null;
240
- };
241
-
242
- return InnerComponent;
243
- }(_react2.default.Component);
244
-
245
- it('should not leak the innerRef prop to the wrapped child', function () {
246
- var OuterComponent = (0, _index2.default)(InnerComponent)(_templateObject);
247
- var ref = jest.fn();
248
-
249
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(OuterComponent, { innerRef: ref }));
250
- var innerComponent = wrapper.find(InnerComponent).first();
251
- var outerComponent = wrapper.find(OuterComponent).first();
252
-
253
- // $FlowFixMe
254
- expect(ref).toHaveBeenCalledWith(innerComponent.node);
255
- expect(innerComponent.prop('innerRef')).toBeFalsy();
256
- expect(outerComponent.node.root).toBeTruthy();
257
- });
258
-
259
- it('should pass the innerRef to the wrapped styled component', function () {
260
- var InnerComponent = _index2.default.View(_templateObject);
261
- var OuterComponent = (0, _index2.default)(InnerComponent)(_templateObject);
262
- var ref = jest.fn();
263
-
264
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(OuterComponent, { innerRef: ref }));
265
- var view = wrapper.find('View').first();
266
- var innerComponent = wrapper.find(InnerComponent).first();
267
- var outerComponent = wrapper.find(OuterComponent).first();
268
-
269
- // $FlowFixMe
270
- expect(ref).toHaveBeenCalledWith(view.node);
271
- expect(outerComponent.node.root).toBeTruthy();
272
- });
273
-
274
- it('should pass innerRef instead of ref to a wrapped stateless functional component', function () {
275
- var InnerComponent = function InnerComponent() {
276
- return null;
277
- };
278
- var OuterComponent = (0, _index2.default)(InnerComponent)(_templateObject);
279
- // NOTE: A ref should always be passed, so we don't need to (setNativeProps feature)
280
-
281
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(OuterComponent, null));
282
- var outerComponent = wrapper.find(OuterComponent).first();
283
- var innerComponent = wrapper.find(InnerComponent).first();
284
-
285
- expect(innerComponent.prop('ref')).toBeFalsy();
286
- expect(innerComponent.prop('innerRef')).toBeTruthy();
287
- expect(outerComponent.node.root).toBeFalsy();
288
- });
289
- });
290
- });
@@ -1,46 +0,0 @@
1
- 'use strict';
2
-
3
- var _react = require('react');
4
-
5
- var _react2 = _interopRequireDefault(_react);
6
-
7
- var _enzyme = require('enzyme');
8
-
9
- var _utils = require('../../test/utils');
10
-
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
-
13
- var styled = void 0;
14
-
15
-
16
- describe('basic', function () {
17
- beforeEach(function () {
18
- styled = (0, _utils.resetNoParserStyled)();
19
- });
20
-
21
- it('should throw a meaningful error when called with null', function () {
22
- var invalidComps = [undefined, null, 123, []];
23
- invalidComps.forEach(function (comp) {
24
- expect(function () {
25
- // $FlowInvalidInputTest
26
- var Comp = styled(comp);
27
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
28
- // $FlowInvalidInputTest
29
- }).toThrow('Cannot create styled-component for component: ' + comp);
30
- });
31
- });
32
-
33
- it('should correctly assemble preprocessed CSS', function () {
34
- var Comp = styled.div([['{ color: red; }']]);
35
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
36
- (0, _utils.expectCSSMatches)('.sc-a {} .b{ color: red; }');
37
- });
38
-
39
- it('should correctly execute passed functions and assemble preprocessed CSS', function () {
40
- var Comp = styled.div([['{ color: ', function () {
41
- return 'red';
42
- }, '; }']]);
43
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
44
- (0, _utils.expectCSSMatches)('.sc-a {} .b{ color: red; }');
45
- });
46
- });