@@ -71,6 +71,34 @@ describe('isStatelessComponent', () => {
71
71
} ) ;
72
72
} ) ;
73
73
74
+ describe ( 'Stateless Function Components with React.cloneElement' , ( ) => {
75
+ it ( 'accepts simple arrow function components' , ( ) => {
76
+ var def = parse ( `
77
+ var AlphaBetters = require('react');
78
+ var Foo = ({ children }) => AlphaBetters.cloneElement(children, null);
79
+ ` ) . get ( 'body' , 1 ) . get ( 'declarations' , [ 0 ] ) . get ( 'init' ) ;
80
+
81
+ expect ( isStatelessComponent ( def ) ) . toBe ( true ) ;
82
+ } ) ;
83
+
84
+ it ( 'accepts simple function expressions components' , ( ) => {
85
+ var def = parse ( `
86
+ var React = require('react');
87
+ let Foo = function({ children }) { return React.cloneElement(children, null); };
88
+ ` ) . get ( 'body' , 1 ) . get ( 'declarations' , [ 0 ] ) . get ( 'init' ) ;
89
+
90
+ expect ( isStatelessComponent ( def ) ) . toBe ( true ) ;
91
+ } ) ;
92
+
93
+ it ( 'accepts simple function declaration components' , ( ) => {
94
+ var def = parse ( `
95
+ var React = require('react');
96
+ function Foo ({ children }) { return React.cloneElement(children, null); }
97
+ ` ) . get ( 'body' , 1 ) ;
98
+ expect ( isStatelessComponent ( def ) ) . toBe ( true ) ;
99
+ } ) ;
100
+ } ) ;
101
+
74
102
describe ( 'Stateless Function Components inside module pattern' , ( ) => {
75
103
it ( '' , ( ) => {
76
104
var def = parse ( `
@@ -79,19 +107,22 @@ describe('isStatelessComponent', () => {
79
107
Bar() { return <div />; },
80
108
Baz: function() { return React.createElement('div'); },
81
109
['hello']: function() { return React.createElement('div'); },
82
- render() { return 7; }
110
+ render() { return 7; },
111
+ world: function({ children }) { return React.cloneElement(children, {}); },
83
112
}
84
113
` ) . get ( 'body' , 1 ) . get ( 'declarations' , 0 ) . get ( 'init' ) ;
85
114
86
115
var bar = def . get ( 'properties' , 0 ) ;
87
116
var baz = def . get ( 'properties' , 1 ) ;
88
117
var hello = def . get ( 'properties' , 2 ) ;
89
118
var render = def . get ( 'properties' , 3 ) ;
119
+ var world = def . get ( 'properties' , 4 ) ;
90
120
91
121
expect ( isStatelessComponent ( bar ) ) . toBe ( true ) ;
92
122
expect ( isStatelessComponent ( baz ) ) . toBe ( true ) ;
93
123
expect ( isStatelessComponent ( hello ) ) . toBe ( true ) ;
94
124
expect ( isStatelessComponent ( render ) ) . toBe ( false ) ;
125
+ expect ( isStatelessComponent ( world ) ) . toBe ( true ) ;
95
126
} ) ;
96
127
} ) ;
97
128
@@ -250,4 +281,3 @@ describe('isStatelessComponent', () => {
250
281
` ) ;
251
282
} ) ;
252
283
} ) ;
253
-
0 commit comments