Skip to content

Commit

Permalink
Added more forwardRef test cases for DevTools (#17642)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored Dec 17, 2019
1 parent 4b0cdf2 commit e84327b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ exports[`Store should show the right display names for special component types 1
▾ <App>
<MyComponent>
<MyComponent> [ForwardRef]
▾ <Anonymous> [ForwardRef]
<MyComponent>
<Custom> [ForwardRef]
<MyComponent> [Memo]
▾ <MyComponent> [Memo]
<MyComponent> [ForwardRef]
Expand Down
9 changes: 9 additions & 0 deletions packages/react-devtools-shared/src/__tests__/store-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,13 @@ describe('Store', () => {

const MyComponent = (props, ref) => null;
const FowardRefComponent = React.forwardRef(MyComponent);
const FowardRefComponentWithAnonymousFunction = React.forwardRef(() => (
<MyComponent />
));
const FowardRefComponentWithCustomDisplayName = React.forwardRef(
MyComponent,
);
FowardRefComponentWithCustomDisplayName.displayName = 'Custom';
const MemoComponent = React.memo(MyComponent);
const MemoForwardRefComponent = React.memo(FowardRefComponent);
const LazyComponent = React.lazy(() => fakeImport(MyComponent));
Expand All @@ -864,6 +871,8 @@ describe('Store', () => {
<React.Fragment>
<MyComponent />
<FowardRefComponent />
<FowardRefComponentWithAnonymousFunction />
<FowardRefComponentWithCustomDisplayName />
<MemoComponent />
<MemoForwardRefComponent />
<React.Suspense fallback="Loading...">
Expand Down
11 changes: 10 additions & 1 deletion packages/react-devtools-shell/src/app/ElementTypes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ function FunctionComponent() {

const MemoFunctionComponent = memo(FunctionComponent);

const ForwardRefComponent = forwardRef((props, ref) => (
const FowardRefComponentWithAnonymousFunction = forwardRef((props, ref) => (
<ClassComponent ref={ref} {...props} />
));
const ForwardRefComponent = forwardRef(function NamedInnerFunction(props, ref) {
return <ClassComponent ref={ref} {...props} />;
});
const FowardRefComponentWithCustomDisplayName = forwardRef((props, ref) => (
<ClassComponent ref={ref} {...props} />
));
FowardRefComponentWithCustomDisplayName.displayName = 'Custom';

const LazyComponent = lazy(() =>
Promise.resolve({
Expand All @@ -58,6 +65,8 @@ export default function ElementTypes() {
<FunctionComponent />
<MemoFunctionComponent />
<ForwardRefComponent />
<FowardRefComponentWithAnonymousFunction />
<FowardRefComponentWithCustomDisplayName />
<LazyComponent />
</Suspense>
</StrictMode>
Expand Down

0 comments on commit e84327b

Please sign in to comment.