Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Oct 8, 2024
1 parent 6dc113e commit ebf041c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import { render, screen } from '@testing-library/react';

import ModalDialog from '../ModalDialog';

jest.mock('../ModalLayer', () => function ModalLayerMock(props) {
jest.mock('../ModalLayer', () => function ModalLayerMock(props: any) {
// eslint-disable-next-line react/prop-types
const { children, ...otherProps } = props;
return (
<modal-layer {...otherProps}>
{children}
</modal-layer>
// @ts-ignore this fake element. (Property 'modal-layer' does not exist on type 'JSX.IntrinsicElements')
<modal-layer {...otherProps}>{children}</modal-layer>
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import userEvent from '@testing-library/user-event';
import ModalLayer from '../ModalLayer';

/* eslint-disable react/prop-types */
jest.mock('../Portal', () => function PortalMock(props) {
jest.mock('../Portal', () => function PortalMock(props: any) {
const { children, ...otherProps } = props;
return (
<paragon-portal {...otherProps}>
{children}
</paragon-portal>
// @ts-ignore this fake element. (Property 'paragon-portal' does not exist on type 'JSX.IntrinsicElements')
<paragon-portal {...otherProps}>{children}</paragon-portal>
);
});

jest.mock('react-focus-on', () => ({
FocusOn: jest.fn().mockImplementation((props) => {
const { children, ...otherProps } = props;
return (
// @ts-ignore this fake element. (Property 'focus-on' does not exist on type 'JSX.IntrinsicElements')
<focus-on data-testid="focus-on" {...otherProps}>{children}</focus-on>
);
}),
Expand Down Expand Up @@ -117,7 +117,7 @@ describe('<ModalLayer />', () => {
);
expect(FocusOn).toHaveBeenCalledWith(
expect.objectContaining({
onEscapeKey: null,
onEscapeKey: undefined,
}),
// note: this 2nd function argument represents the
// `refOrContext` (in this case, the context value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<Portal />', () => {

const portalRoot = getPortalRoot();
expect(portalRoot).not.toBeNull();
expect(portalRoot.children[0].id).toBe('portal-content-a');
expect(portalRoot!.children[0].id).toBe('portal-content-a');
});

it('renders both contents in a single #paragon-portal-root div', () => {
Expand All @@ -38,7 +38,7 @@ describe('<Portal />', () => {

const portalRoot = getPortalRoot();
expect(portalRoot).not.toBeNull();
expect(portalRoot.children[0].id).toBe('portal-content-a');
expect(portalRoot.children[1].id).toBe('portal-content-b');
expect(portalRoot!.children[0].id).toBe('portal-content-a');
expect(portalRoot!.children[1].id).toBe('portal-content-b');
});
});

0 comments on commit ebf041c

Please sign in to comment.