@@ -11,6 +11,7 @@ import {
11
11
getDisplayName ,
12
12
getDisplayNameForReactElement ,
13
13
} from 'react-devtools-shared/src/utils' ;
14
+ import { format } from 'react-devtools-shared/src/backend/utils' ;
14
15
import {
15
16
REACT_SUSPENSE_LIST_TYPE as SuspenseList ,
16
17
REACT_STRICT_MODE_TYPE as StrictMode ,
@@ -45,6 +46,7 @@ describe('utils', () => {
45
46
expect ( getDisplayName ( FauxComponent , 'Fallback' ) ) . toEqual ( 'Fallback' ) ;
46
47
} ) ;
47
48
} ) ;
49
+
48
50
describe ( 'getDisplayNameForReactElement' , ( ) => {
49
51
it ( 'should return correct display name for an element with function type' , ( ) => {
50
52
function FauxComponent ( ) { }
@@ -54,29 +56,58 @@ describe('utils', () => {
54
56
'OverrideDisplayName' ,
55
57
) ;
56
58
} ) ;
59
+
57
60
it ( 'should return correct display name for an element with a type of StrictMode' , ( ) => {
58
61
const element = createElement ( StrictMode ) ;
59
62
expect ( getDisplayNameForReactElement ( element ) ) . toEqual ( 'StrictMode' ) ;
60
63
} ) ;
64
+
61
65
it ( 'should return correct display name for an element with a type of SuspenseList' , ( ) => {
62
66
const element = createElement ( SuspenseList ) ;
63
67
expect ( getDisplayNameForReactElement ( element ) ) . toEqual ( 'SuspenseList' ) ;
64
68
} ) ;
69
+
65
70
it ( 'should return NotImplementedInDevtools for an element with invalid symbol type' , ( ) => {
66
71
const element = createElement ( Symbol ( 'foo' ) ) ;
67
72
expect ( getDisplayNameForReactElement ( element ) ) . toEqual (
68
73
'NotImplementedInDevtools' ,
69
74
) ;
70
75
} ) ;
76
+
71
77
it ( 'should return NotImplementedInDevtools for an element with invalid type' , ( ) => {
72
78
const element = createElement ( true ) ;
73
79
expect ( getDisplayNameForReactElement ( element ) ) . toEqual (
74
80
'NotImplementedInDevtools' ,
75
81
) ;
76
82
} ) ;
83
+
77
84
it ( 'should return Element for null type' , ( ) => {
78
85
const element = createElement ( ) ;
79
86
expect ( getDisplayNameForReactElement ( element ) ) . toEqual ( 'Element' ) ;
80
87
} ) ;
81
88
} ) ;
89
+
90
+ describe ( 'format' , ( ) => {
91
+ it ( 'should format simple strings' , ( ) => {
92
+ expect ( format ( 'a' , 'b' , 'c' ) ) . toEqual ( 'a b c' ) ;
93
+ } ) ;
94
+
95
+ it ( 'should format multiple argument types' , ( ) => {
96
+ expect ( format ( 'abc' , 123 , true ) ) . toEqual ( 'abc 123 true' ) ;
97
+ } ) ;
98
+
99
+ it ( 'should support string substitutions' , ( ) => {
100
+ expect ( format ( 'a %s b %s c' , 123 , true ) ) . toEqual ( 'a 123 b true c' ) ;
101
+ } ) ;
102
+
103
+ it ( 'should gracefully handle Symbol types' , ( ) => {
104
+ expect ( format ( Symbol ( 'a' ) , 'b' , Symbol ( 'c' ) ) ) . toEqual (
105
+ 'Symbol(a) b Symbol(c)' ,
106
+ ) ;
107
+ } ) ;
108
+
109
+ it ( 'should gracefully handle Symbol type for the first argument' , ( ) => {
110
+ expect ( format ( Symbol ( 'abc' ) , 123 ) ) . toEqual ( 'Symbol(abc) 123' ) ;
111
+ } ) ;
112
+ } ) ;
82
113
} ) ;
0 commit comments