Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 10, 2024
1 parent 1d9e094 commit 514bc9b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
21 changes: 20 additions & 1 deletion packages/components/src/confirm-dialog/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@ import { ConfirmDialog } from '..';

const noop = () => {};

describe( 'Confirm', () => {
describe( 'Confirm Dialog', () => {
// Mock `matchMedia` so that all animations are skipped,
// since js-dom does not support fully CSS animations.
const originalMatchMedia = window.matchMedia;
const mockedMatchMedia = jest.fn( ( query: string ) => {
if ( /prefers-reduced-motion/.test( query ) ) {
return { matches: true } as ReturnType< typeof window.matchMedia >;
}

return originalMatchMedia( query );
} );

beforeAll( () => {
window.matchMedia = jest.fn( mockedMatchMedia );
} );

afterAll( () => {
window.matchMedia = originalMatchMedia;
} );

describe( 'Confirm component', () => {
describe( 'Structure', () => {
it( 'should render correctly', () => {
Expand Down
19 changes: 19 additions & 0 deletions packages/components/src/modal/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ import type { ModalProps } from '../types';
const noop = () => {};

describe( 'Modal', () => {
// Mock `matchMedia` so that all animations are skipped,
// since js-dom does not support fully CSS animations.
const originalMatchMedia = window.matchMedia;
const mockedMatchMedia = jest.fn( ( query: string ) => {
if ( /prefers-reduced-motion/.test( query ) ) {
return { matches: true } as ReturnType< typeof window.matchMedia >;
}

return originalMatchMedia( query );
} );

beforeAll( () => {
window.matchMedia = jest.fn( mockedMatchMedia );
} );

afterAll( () => {
window.matchMedia = originalMatchMedia;
} );

it( 'applies the aria-describedby attribute when provided', () => {
render(
<Modal
Expand Down

0 comments on commit 514bc9b

Please sign in to comment.