|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. |
| 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 | + |
| 8 | +import React from 'react'; |
| 9 | +import setPrettyPrint from './setPrettyPrint'; |
| 10 | +import prettyFormat from '..'; |
| 11 | + |
| 12 | +const {ReactElement} = prettyFormat.plugins; |
| 13 | + |
| 14 | +setPrettyPrint([ReactElement]); |
| 15 | + |
| 16 | +describe('ReactElement Plugin', () => { |
| 17 | + let forwardRefComponent: { |
| 18 | + (_props: any, _ref: any): any; |
| 19 | + displayName?: string; |
| 20 | + }; |
| 21 | + |
| 22 | + let forwardRefExample: ReturnType<typeof React.forwardRef>; |
| 23 | + |
| 24 | + beforeEach(() => { |
| 25 | + forwardRefComponent = (_props, _ref) => null; |
| 26 | + |
| 27 | + forwardRefExample = React.forwardRef(forwardRefComponent); |
| 28 | + |
| 29 | + forwardRefExample.displayName = undefined; |
| 30 | + }); |
| 31 | + |
| 32 | + test('serializes forwardRef without displayName', () => { |
| 33 | + forwardRefExample = React.forwardRef((_props, _ref) => null); |
| 34 | + expect(React.createElement(forwardRefExample)).toPrettyPrintTo( |
| 35 | + '<ForwardRef />', |
| 36 | + ); |
| 37 | + }); |
| 38 | + |
| 39 | + test('serializes forwardRef with displayName', () => { |
| 40 | + forwardRefExample.displayName = 'Display'; |
| 41 | + expect(React.createElement(forwardRefExample)).toPrettyPrintTo( |
| 42 | + '<Display />', |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + test('serializes forwardRef component with displayName', () => { |
| 47 | + forwardRefComponent.displayName = 'Display'; |
| 48 | + expect(React.createElement(forwardRefExample)).toPrettyPrintTo( |
| 49 | + '<ForwardRef(Display) />', |
| 50 | + ); |
| 51 | + }); |
| 52 | +}); |
0 commit comments