@@ -11,48 +11,30 @@ import {getDisplayName} from 'react-devtools-shared/src/utils';
11
11
12
12
describe ( 'utils' , ( ) => {
13
13
describe ( 'getDisplayName' , ( ) => {
14
- const fallbackName = 'TestFallbackName' ;
15
-
16
- it ( 'should return default fallback name for empty object' , ( ) => {
17
- const result = getDisplayName ( { } ) ;
18
- expect ( result ) . toEqual ( 'Anonymous' ) ;
19
- } ) ;
20
-
21
- it ( 'should return displayName property from object' , ( ) => {
22
- const obj = {
23
- displayName : 'TestDisplayName' ,
24
- } ;
25
- const result = getDisplayName ( obj ) ;
26
- expect ( result ) . toEqual ( obj . displayName ) ;
14
+ it ( 'should return a function name' , ( ) => {
15
+ function FauxComponent ( ) { }
16
+ expect ( getDisplayName ( FauxComponent ) ) . toEqual ( 'FauxComponent' ) ;
27
17
} ) ;
28
18
29
- it ( 'should return name property from object' , ( ) => {
30
- const obj = {
31
- name : 'TestName' ,
32
- } ;
33
- const result = getDisplayName ( obj ) ;
34
- expect ( result ) . toEqual ( obj . name ) ;
19
+ it ( 'should return a displayName name if specified' , ( ) => {
20
+ function FauxComponent ( ) { }
21
+ FauxComponent . displayName = 'OverrideDisplayName' ;
22
+ expect ( getDisplayName ( FauxComponent ) ) . toEqual ( 'OverrideDisplayName' ) ;
35
23
} ) ;
36
24
37
- it ( 'should return provided fallback name for empty object' , ( ) => {
38
- const result = getDisplayName ( { } , fallbackName ) ;
39
- expect ( result ) . toEqual ( fallbackName ) ;
25
+ it ( 'should return the fallback for anonymous functions' , ( ) => {
26
+ expect ( getDisplayName ( ( ) => { } , 'Fallback' ) ) . toEqual ( 'Fallback' ) ;
40
27
} ) ;
41
28
42
- it ( 'should provide fallback name when displayName prop is not a string' , ( ) => {
43
- const obj = {
44
- displayName : { } ,
45
- } ;
46
- const result = getDisplayName ( obj , fallbackName ) ;
47
- expect ( result ) . toEqual ( fallbackName ) ;
29
+ it ( 'should return Anonymous for anonymous functions without a fallback' , ( ) => {
30
+ expect ( getDisplayName ( ( ) => { } ) ) . toEqual ( 'Anonymous' ) ;
48
31
} ) ;
49
32
50
- it ( 'should provide fallback name when name prop is not a string' , ( ) => {
51
- const obj = {
52
- name : { } ,
53
- } ;
54
- const result = getDisplayName ( obj , fallbackName ) ;
55
- expect ( result ) . toEqual ( fallbackName ) ;
33
+ // Simulate a reported bug:
34
+ // https://github.com/facebook/react/issues/16685
35
+ it ( 'should return a fallback when the name prop is not a string' , ( ) => {
36
+ const FauxComponent = { name : { } } ;
37
+ expect ( getDisplayName ( FauxComponent , 'Fallback' ) ) . toEqual ( 'Fallback' ) ;
56
38
} ) ;
57
39
} ) ;
58
40
} ) ;
0 commit comments