Skip to content

Commit

Permalink
Type check (deephaven#2094)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jun 21, 2024
1 parent 8886d49 commit f1ccbb2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/react-hooks/src/ElementUtils.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { createElement } from 'react';
import { Text } from '@adobe/react-spectrum';
import { ItemElement, Item, Text } from '@deephaven/components';
import { isElementOfType } from './ElementUtils';

beforeEach(() => {
jest.clearAllMocks();
expect.hasAssertions();
});

describe('isElementOfType', () => {
function MockComponent() {
return null;
Expand All @@ -21,4 +26,16 @@ describe('isElementOfType', () => {
expect(isElementOfType(element, type)).toBe(expected);
}
);

it('should derive the `type` prop', () => {
const element: ItemElement = createElement(Item);

if (isElementOfType(element, Item)) {
// This is a type check that verifies the type guard narrows this to the
// `Item` function instead of `string | JSXElementConstructor<any>`. This
// proves that #2094 is working as expected. Namely, the compiler will
// complain if it thinks `type` could be a string.
expect(element.type.name).toEqual(Item.name);
}
});
});

0 comments on commit f1ccbb2

Please sign in to comment.