|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @flow |
| 8 | + */ |
| 9 | + |
| 10 | +import {getDisplayName} from 'react-devtools-shared/src/utils'; |
| 11 | + |
| 12 | +describe('utils', () => { |
| 13 | + describe('getDisplayName', () => { |
| 14 | + it('should return a function name', () => { |
| 15 | + function FauxComponent() {} |
| 16 | + expect(getDisplayName(FauxComponent)).toEqual('FauxComponent'); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should return a displayName name if specified', () => { |
| 20 | + function FauxComponent() {} |
| 21 | + FauxComponent.displayName = 'OverrideDisplayName'; |
| 22 | + expect(getDisplayName(FauxComponent)).toEqual('OverrideDisplayName'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should return the fallback for anonymous functions', () => { |
| 26 | + expect(getDisplayName(() => {}, 'Fallback')).toEqual('Fallback'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return Anonymous for anonymous functions without a fallback', () => { |
| 30 | + expect(getDisplayName(() => {})).toEqual('Anonymous'); |
| 31 | + }); |
| 32 | + |
| 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'); |
| 38 | + }); |
| 39 | + }); |
| 40 | +}); |
0 commit comments