@@ -14,11 +14,11 @@ let React;
1414let ReactDOM ;
1515let ReactTestUtils ;
1616
17- function StatelessComponent ( props ) {
17+ function FunctionComponent ( props ) {
1818 return < div > { props . name } </ div > ;
1919}
2020
21- describe ( 'ReactStatelessComponent ' , ( ) => {
21+ describe ( 'ReactFunctionComponent ' , ( ) => {
2222 beforeEach ( ( ) => {
2323 jest . resetModuleRegistry ( ) ;
2424 PropTypes = require ( 'prop-types' ) ;
@@ -29,15 +29,15 @@ describe('ReactStatelessComponent', () => {
2929
3030 it ( 'should render stateless component' , ( ) => {
3131 const el = document . createElement ( 'div' ) ;
32- ReactDOM . render ( < StatelessComponent name = "A" /> , el ) ;
32+ ReactDOM . render ( < FunctionComponent name = "A" /> , el ) ;
3333
3434 expect ( el . textContent ) . toBe ( 'A' ) ;
3535 } ) ;
3636
3737 it ( 'should update stateless component' , ( ) => {
3838 class Parent extends React . Component {
3939 render ( ) {
40- return < StatelessComponent { ...this . props } /> ;
40+ return < FunctionComponent { ...this . props } /> ;
4141 }
4242 }
4343
@@ -52,7 +52,7 @@ describe('ReactStatelessComponent', () => {
5252 it ( 'should unmount stateless component' , ( ) => {
5353 const container = document . createElement ( 'div' ) ;
5454
55- ReactDOM . render ( < StatelessComponent name = "A" /> , container ) ;
55+ ReactDOM . render ( < FunctionComponent name = "A" /> , container ) ;
5656 expect ( container . textContent ) . toBe ( 'A' ) ;
5757
5858 ReactDOM . unmountComponentAtNode ( container ) ;
@@ -98,42 +98,42 @@ describe('ReactStatelessComponent', () => {
9898 expect ( el . textContent ) . toBe ( 'mest' ) ;
9999 } ) ;
100100
101- it ( 'should warn for getDerivedStateFromProps on a functional component' , ( ) => {
102- function StatelessComponentWithChildContext ( ) {
101+ it ( 'should warn for getDerivedStateFromProps on a function component' , ( ) => {
102+ function FunctionComponentWithChildContext ( ) {
103103 return null ;
104104 }
105- StatelessComponentWithChildContext . getDerivedStateFromProps = function ( ) { } ;
105+ FunctionComponentWithChildContext . getDerivedStateFromProps = function ( ) { } ;
106106
107107 const container = document . createElement ( 'div' ) ;
108108
109109 expect ( ( ) =>
110- ReactDOM . render ( < StatelessComponentWithChildContext /> , container ) ,
110+ ReactDOM . render ( < FunctionComponentWithChildContext /> , container ) ,
111111 ) . toWarnDev (
112- 'StatelessComponentWithChildContext: Stateless ' +
113- 'functional components do not support getDerivedStateFromProps.' ,
112+ 'FunctionComponentWithChildContext: Function ' +
113+ 'components do not support getDerivedStateFromProps.' ,
114114 { withoutStack : true } ,
115115 ) ;
116116 } ) ;
117117
118- it ( 'should warn for childContextTypes on a functional component' , ( ) => {
119- function StatelessComponentWithChildContext ( props ) {
118+ it ( 'should warn for childContextTypes on a function component' , ( ) => {
119+ function FunctionComponentWithChildContext ( props ) {
120120 return < div > { props . name } </ div > ;
121121 }
122122
123- StatelessComponentWithChildContext . childContextTypes = {
123+ FunctionComponentWithChildContext . childContextTypes = {
124124 foo : PropTypes . string ,
125125 } ;
126126
127127 const container = document . createElement ( 'div' ) ;
128128
129129 expect ( ( ) =>
130130 ReactDOM . render (
131- < StatelessComponentWithChildContext name = "A" /> ,
131+ < FunctionComponentWithChildContext name = "A" /> ,
132132 container ,
133133 ) ,
134134 ) . toWarnDev (
135- 'StatelessComponentWithChildContext (...): childContextTypes cannot ' +
136- 'be defined on a functional component.' ,
135+ 'FunctionComponentWithChildContext (...): childContextTypes cannot ' +
136+ 'be defined on a function component.' ,
137137 { withoutStack : true } ,
138138 ) ;
139139 } ) ;
@@ -161,12 +161,12 @@ describe('ReactStatelessComponent', () => {
161161 ReactTestUtils . renderIntoDocument ( < Child test = "test" /> ) ;
162162 } ) . toThrowError (
163163 __DEV__
164- ? 'Stateless function components cannot have refs.'
164+ ? 'Function components cannot have refs.'
165165 : // It happens because we don't save _owner in production for
166- // functional components.
166+ // function components.
167167 'Element ref was specified as a string (me) but no owner was set. This could happen for one of' +
168168 ' the following reasons:\n' +
169- '1. You may be adding a ref to a functional component\n' +
169+ '1. You may be adding a ref to a function component\n' +
170170 "2. You may be adding a ref to a component that was not created inside a component's render method\n" +
171171 '3. You have multiple copies of React loaded\n' +
172172 'See https://fb.me/react-refs-must-have-owner for more information.' ,
@@ -182,7 +182,7 @@ describe('ReactStatelessComponent', () => {
182182 render ( ) {
183183 return (
184184 < Indirection >
185- < StatelessComponent name = "A" ref = "stateless" />
185+ < FunctionComponent name = "A" ref = "stateless" />
186186 </ Indirection >
187187 ) ;
188188 }
@@ -191,10 +191,10 @@ describe('ReactStatelessComponent', () => {
191191 expect ( ( ) =>
192192 ReactTestUtils . renderIntoDocument ( < ParentUsingStringRef /> ) ,
193193 ) . toWarnDev (
194- 'Warning: Stateless function components cannot be given refs. ' +
194+ 'Warning: Function components cannot be given refs. ' +
195195 'Attempts to access this ref will fail.\n\nCheck the render method ' +
196196 'of `ParentUsingStringRef`.\n' +
197- ' in StatelessComponent (at **)\n' +
197+ ' in FunctionComponent (at **)\n' +
198198 ' in div (at **)\n' +
199199 ' in Indirection (at **)\n' +
200200 ' in ParentUsingStringRef (at **)' ,
@@ -213,7 +213,7 @@ describe('ReactStatelessComponent', () => {
213213 render ( ) {
214214 return (
215215 < Indirection >
216- < StatelessComponent
216+ < FunctionComponent
217217 name = "A"
218218 ref = { arg => {
219219 expect ( arg ) . toBe ( null ) ;
@@ -227,10 +227,10 @@ describe('ReactStatelessComponent', () => {
227227 expect ( ( ) =>
228228 ReactTestUtils . renderIntoDocument ( < ParentUsingFunctionRef /> ) ,
229229 ) . toWarnDev (
230- 'Warning: Stateless function components cannot be given refs. ' +
230+ 'Warning: Function components cannot be given refs. ' +
231231 'Attempts to access this ref will fail.\n\nCheck the render method ' +
232232 'of `ParentUsingFunctionRef`.\n' +
233- ' in StatelessComponent (at **)\n' +
233+ ' in FunctionComponent (at **)\n' +
234234 ' in div (at **)\n' +
235235 ' in Indirection (at **)\n' +
236236 ' in ParentUsingFunctionRef (at **)' ,
@@ -244,7 +244,7 @@ describe('ReactStatelessComponent', () => {
244244 // When owner uses JSX, we can use exact line location to dedupe warnings
245245 class AnonymousParentUsingJSX extends React . Component {
246246 render ( ) {
247- return < StatelessComponent name = "A" ref = { ( ) => { } } /> ;
247+ return < FunctionComponent name = "A" ref = { ( ) => { } } /> ;
248248 }
249249 }
250250 Object . defineProperty ( AnonymousParentUsingJSX , 'name' , { value : undefined } ) ;
@@ -255,9 +255,7 @@ describe('ReactStatelessComponent', () => {
255255 instance1 = ReactTestUtils . renderIntoDocument (
256256 < AnonymousParentUsingJSX /> ,
257257 ) ;
258- } ) . toWarnDev (
259- 'Warning: Stateless function components cannot be given refs.' ,
260- ) ;
258+ } ) . toWarnDev ( 'Warning: Function components cannot be given refs.' ) ;
261259 // Should be deduped (offending element is on the same line):
262260 instance1 . forceUpdate ( ) ;
263261 // Should also be deduped (offending element is on the same line):
@@ -266,7 +264,7 @@ describe('ReactStatelessComponent', () => {
266264 // When owner doesn't use JSX, and is anonymous, we warn once per internal instance.
267265 class AnonymousParentNotUsingJSX extends React . Component {
268266 render ( ) {
269- return React . createElement ( StatelessComponent , {
267+ return React . createElement ( FunctionComponent , {
270268 name : 'A' ,
271269 ref : ( ) => { } ,
272270 } ) ;
@@ -281,20 +279,18 @@ describe('ReactStatelessComponent', () => {
281279 instance2 = ReactTestUtils . renderIntoDocument (
282280 < AnonymousParentNotUsingJSX /> ,
283281 ) ;
284- } ) . toWarnDev (
285- 'Warning: Stateless function components cannot be given refs.' ,
286- ) ;
282+ } ) . toWarnDev ( 'Warning: Function components cannot be given refs.' ) ;
287283 // Should be deduped (same internal instance, no additional warnings)
288284 instance2 . forceUpdate ( ) ;
289285 // Could not be deduped (different internal instance):
290286 expect ( ( ) =>
291287 ReactTestUtils . renderIntoDocument ( < AnonymousParentNotUsingJSX /> ) ,
292- ) . toWarnDev ( 'Warning: Stateless function components cannot be given refs.' ) ;
288+ ) . toWarnDev ( 'Warning: Function components cannot be given refs.' ) ;
293289
294290 // When owner doesn't use JSX, but is named, we warn once per owner name
295291 class NamedParentNotUsingJSX extends React . Component {
296292 render ( ) {
297- return React . createElement ( StatelessComponent , {
293+ return React . createElement ( FunctionComponent , {
298294 name : 'A' ,
299295 ref : ( ) => { } ,
300296 } ) ;
@@ -303,9 +299,7 @@ describe('ReactStatelessComponent', () => {
303299 let instance3 ;
304300 expect ( ( ) => {
305301 instance3 = ReactTestUtils . renderIntoDocument ( < NamedParentNotUsingJSX /> ) ;
306- } ) . toWarnDev (
307- 'Warning: Stateless function components cannot be given refs.' ,
308- ) ;
302+ } ) . toWarnDev ( 'Warning: Function components cannot be given refs.' ) ;
309303 // Should be deduped (same owner name, no additional warnings):
310304 instance3 . forceUpdate ( ) ;
311305 // Should also be deduped (same owner name, no additional warnings):
@@ -337,7 +331,7 @@ describe('ReactStatelessComponent', () => {
337331 }
338332
339333 expect ( ( ) => ReactTestUtils . renderIntoDocument ( < Parent /> ) ) . toWarnDev (
340- 'Warning: Stateless function components cannot be given refs. ' +
334+ 'Warning: Function components cannot be given refs. ' +
341335 'Attempts to access this ref will fail.\n\nCheck the render method ' +
342336 'of `Parent`.\n' +
343337 ' in Child (at **)\n' +
0 commit comments