|
7 | 7 | * @flow
|
8 | 8 | */
|
9 | 9 |
|
10 |
| -import{getDisplayName}from'react-devtools-shared/src/utils'; |
| 10 | +import{ |
| 11 | +getDisplayName, |
| 12 | +getDisplayNameForReactElement, |
| 13 | +}from'react-devtools-shared/src/utils'; |
| 14 | +import{ |
| 15 | +REACT_SUSPENSE_LIST_TYPEasSuspenseList, |
| 16 | +REACT_STRICT_MODE_TYPEasStrictMode, |
| 17 | +}from'shared/ReactSymbols'; |
| 18 | +import{createElement}from'react/src/ReactElement'; |
11 | 19 |
|
12 | 20 | describe('utils',()=>{
|
13 | 21 | describe('getDisplayName',()=>{
|
@@ -37,4 +45,38 @@ describe('utils', () => {
|
37 | 45 | expect(getDisplayName(FauxComponent,'Fallback')).toEqual('Fallback');
|
38 | 46 | });
|
39 | 47 | });
|
| 48 | +describe('getDisplayNameForReactElement',()=>{ |
| 49 | +it('should return correct display name for an element with function type',()=>{ |
| 50 | +functionFauxComponent(){} |
| 51 | +FauxComponent.displayName='OverrideDisplayName'; |
| 52 | +constelement=createElement(FauxComponent); |
| 53 | +expect(getDisplayNameForReactElement(element)).toEqual( |
| 54 | +'OverrideDisplayName', |
| 55 | +); |
| 56 | +}); |
| 57 | +it('should return correct display name for an element with a type of StrictMode',()=>{ |
| 58 | +constelement=createElement(StrictMode); |
| 59 | +expect(getDisplayNameForReactElement(element)).toEqual('StrictMode'); |
| 60 | +}); |
| 61 | +it('should return correct display name for an element with a type of SuspenseList',()=>{ |
| 62 | +constelement=createElement(SuspenseList); |
| 63 | +expect(getDisplayNameForReactElement(element)).toEqual('SuspenseList'); |
| 64 | +}); |
| 65 | +it('should return NotImplementedInDevtools for an element with invalid symbol type',()=>{ |
| 66 | +constelement=createElement(Symbol('foo')); |
| 67 | +expect(getDisplayNameForReactElement(element)).toEqual( |
| 68 | +'NotImplementedInDevtools', |
| 69 | +); |
| 70 | +}); |
| 71 | +it('should return NotImplementedInDevtools for an element with invalid type',()=>{ |
| 72 | +constelement=createElement(true); |
| 73 | +expect(getDisplayNameForReactElement(element)).toEqual( |
| 74 | +'NotImplementedInDevtools', |
| 75 | +); |
| 76 | +}); |
| 77 | +it('should return Element for null type',()=>{ |
| 78 | +constelement=createElement(); |
| 79 | +expect(getDisplayNameForReactElement(element)).toEqual('Element'); |
| 80 | +}); |
| 81 | +}); |
40 | 82 | });
|
0 commit comments