@@ -11,6 +11,7 @@ import {
1111 getDisplayName ,
1212 getDisplayNameForReactElement ,
1313} from 'react-devtools-shared/src/utils' ;
14+ import { format } from 'react-devtools-shared/src/backend/utils' ;
1415import {
1516 REACT_SUSPENSE_LIST_TYPE as SuspenseList ,
1617 REACT_STRICT_MODE_TYPE as StrictMode ,
@@ -45,6 +46,7 @@ describe('utils', () => {
4546 expect ( getDisplayName ( FauxComponent , 'Fallback' ) ) . toEqual ( 'Fallback' ) ;
4647 } ) ;
4748 } ) ;
49+
4850 describe ( 'getDisplayNameForReactElement' , ( ) => {
4951 it ( 'should return correct display name for an element with function type' , ( ) => {
5052 function FauxComponent ( ) { }
@@ -54,29 +56,58 @@ describe('utils', () => {
5456 'OverrideDisplayName' ,
5557 ) ;
5658 } ) ;
59+
5760 it ( 'should return correct display name for an element with a type of StrictMode' , ( ) => {
5861 const element = createElement ( StrictMode ) ;
5962 expect ( getDisplayNameForReactElement ( element ) ) . toEqual ( 'StrictMode' ) ;
6063 } ) ;
64+
6165 it ( 'should return correct display name for an element with a type of SuspenseList' , ( ) => {
6266 const element = createElement ( SuspenseList ) ;
6367 expect ( getDisplayNameForReactElement ( element ) ) . toEqual ( 'SuspenseList' ) ;
6468 } ) ;
69+
6570 it ( 'should return NotImplementedInDevtools for an element with invalid symbol type' , ( ) => {
6671 const element = createElement ( Symbol ( 'foo' ) ) ;
6772 expect ( getDisplayNameForReactElement ( element ) ) . toEqual (
6873 'NotImplementedInDevtools' ,
6974 ) ;
7075 } ) ;
76+
7177 it ( 'should return NotImplementedInDevtools for an element with invalid type' , ( ) => {
7278 const element = createElement ( true ) ;
7379 expect ( getDisplayNameForReactElement ( element ) ) . toEqual (
7480 'NotImplementedInDevtools' ,
7581 ) ;
7682 } ) ;
83+
7784 it ( 'should return Element for null type' , ( ) => {
7885 const element = createElement ( ) ;
7986 expect ( getDisplayNameForReactElement ( element ) ) . toEqual ( 'Element' ) ;
8087 } ) ;
8188 } ) ;
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+ } ) ;
82113} ) ;
0 commit comments