Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import {extractHOCNames} from 'react-devtools-shared/src/backend/views/utils';

describe('extractHOCNames', () => {
it('should extract nested HOC names in order', () => {
expect(extractHOCNames('Memo(Forget(Foo))')).toEqual({
baseComponentName: 'Foo',
hocNames: ['Memo', 'Forget'],
});
});

it('should handle a single HOC', () => {
expect(extractHOCNames('Memo(Foo)')).toEqual({
baseComponentName: 'Foo',
hocNames: ['Memo'],
});
});

it('should return the original name when there are no HOCs', () => {
expect(extractHOCNames('Foo')).toEqual({
baseComponentName: 'Foo',
hocNames: [],
});
});
});
2 changes: 1 addition & 1 deletion packages/react-devtools-shared/src/backend/views/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export function extractHOCNames(displayName: string): {
} {
if (!displayName) return {baseComponentName: '', hocNames: []};

const hocRegex = /([A-Z][a-zA-Z0-9]*?)\((.*)\)/g;
const hocRegex = /^([A-Z][a-zA-Z0-9]*?)\((.*)\)$/;
const hocNames: string[] = [];
let baseComponentName = displayName;
let match;
Expand Down