From c390ab3643612dc08ca4bebadc5b0377e9e7eb79 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sat, 16 May 2020 00:56:50 +0200 Subject: [PATCH] Add test for displayName on React.memo components (#18925) * Add test for displayName on React.memo components * Added extra memo displayName test Co-authored-by: Brian Vaughn --- .../src/__tests__/ReactMemo-test.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/react-reconciler/src/__tests__/ReactMemo-test.js b/packages/react-reconciler/src/__tests__/ReactMemo-test.js index 24788e0e87..5be63d65a3 100644 --- a/packages/react-reconciler/src/__tests__/ReactMemo-test.js +++ b/packages/react-reconciler/src/__tests__/ReactMemo-test.js @@ -497,5 +497,44 @@ describe('memo', () => { expect(root).toMatchRenderedOutput('1'); }); }); + + it('should honor a displayName if set on the memo wrapper in warnings', () => { + const MemoComponent = React.memo(function Component(props) { + return
; + }); + MemoComponent.displayName = 'Foo'; + MemoComponent.propTypes = { + required: PropTypes.string.isRequired, + }; + + expect(() => + ReactNoop.render(), + ).toErrorDev( + 'Warning: Failed prop type: The prop `required` is marked as required in ' + + '`Foo`, but its value is `undefined`.\n' + + ' in Foo (at **)', + ); + }); + + it('should honor a inner displayName if set on the wrapped function', () => { + function Component(props) { + return
; + } + Component.displayName = 'Foo'; + + const MemoComponent = React.memo(Component); + MemoComponent.displayName = 'Bar'; + MemoComponent.propTypes = { + required: PropTypes.string.isRequired, + }; + + expect(() => + ReactNoop.render(), + ).toErrorDev( + 'Warning: Failed prop type: The prop `required` is marked as required in ' + + '`Foo`, but its value is `undefined`.\n' + + ' in Foo (at **)', + ); + }); } });