diff --git a/src/components/utils/__tests__/isOfType.test.tsx b/src/components/utils/__tests__/isOfType.test.tsx
new file mode 100644
index 0000000000..7946902e3e
--- /dev/null
+++ b/src/components/utils/__tests__/isOfType.test.tsx
@@ -0,0 +1,76 @@
+import React from 'react';
+
+import {render, screen} from '../../../../test-utils/utils';
+import {isOfType} from '../isOfType';
+
+function Test(props: React.PropsWithChildren<{matcher: (c: unknown) => boolean}>) {
+ const child = React.Children.only(props.children);
+
+ return props.matcher(child) ? 'correct' : 'wrong';
+}
+
+describe('isOfType', () => {
+ test('should match type of component', () => {
+ const Component = () => null;
+
+ render(
+
(Component: React.ComponentType
) { +export function isOfType
(Component: React.ComponentType
| string) { return function isMatching( - component: React.ReactNode, - ): component is React.ReactElement
{ + component: unknown, + ): component is React.ReactElement
{ if (!React.isValidElement(component)) { return false; } const {type} = component; + if (type === Component) { + return true; + } + + if (typeof Component === 'string' || typeof type === 'string') { + return false; + } - return ( - type === React.Component || - (type as React.ComponentType).displayName === Component.displayName - ); + const displayName = (type as React.ComponentType).displayName; + return Boolean(displayName && displayName === Component.displayName); }; }