Skip to content

Commit

Permalink
Disable modal animations in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 10, 2024
1 parent 0658696 commit 25c95c3
Show file tree
Hide file tree
Showing 4 changed files with 77 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/guide/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ const defaultProps = {
};

describe( 'Guide', () => {
// 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( 'renders nothing when there are no pages', () => {
render( <Guide { ...defaultProps } pages={ [] } /> );
expect( screen.queryByRole( 'dialog' ) ).not.toBeInTheDocument();
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
19 changes: 19 additions & 0 deletions packages/components/src/tooltip/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ const hoverOutside = async () => {
};

describe( 'Tooltip', () => {
// 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( 'basic behavior', () => {
it( 'should not render the tooltip if multiple children are passed', async () => {
render(
Expand Down

0 comments on commit 25c95c3

Please sign in to comment.