Skip to content

Commit

Permalink
[test] Fix flaky browser tests (#1371)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks authored Feb 20, 2025
1 parent 49bcc0c commit be07bd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions packages/react/src/avatar/fallback/AvatarFallback.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { Mock } from 'vitest';
import { Avatar } from '@base-ui-components/react/avatar';
import { describeConformance, createRenderer } from '#test-utils';
import { waitFor } from '@mui/internal-test-utils';
import { describeConformance, createRenderer, isJSDOM } from '#test-utils';
import { useImageLoadingStatus } from '../image/useImageLoadingStatus';

vi.mock('../image/useImageLoadingStatus');
Expand Down Expand Up @@ -30,7 +31,9 @@ describe('<Avatar.Fallback />', () => {
</Avatar.Root>,
);

expect(queryByTestId('fallback')).to.equal(null);
await waitFor(() => {
expect(queryByTestId('fallback')).to.equal(null);
});
});

it('should render the fallback if the image fails to load', async () => {
Expand All @@ -43,10 +46,12 @@ describe('<Avatar.Fallback />', () => {
</Avatar.Root>,
);

expect(queryByText('AC')).to.not.equal(null);
await waitFor(() => {
expect(queryByText('AC')).not.to.equal(null);
});
});

describe('prop: delay', () => {
describe.skipIf(!isJSDOM)('prop: delay', () => {
const { clock, render: renderFakeTimers } = createRenderer();

clock.withFakeTimers();
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/menu/root/MenuRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1135,9 +1135,9 @@ describe('<Menu.Root />', () => {
});
});

it('should close the menu when the trigger is no longer hovered', async () => {
it.skipIf(!isJSDOM)('should close the menu when the trigger is no longer hovered', async () => {
const { getByRole, queryByRole } = await render(
<Menu.Root openOnHover delay={0}>
<Menu.Root openOnHover delay={0} modal={false}>
<Menu.Trigger>Open</Menu.Trigger>
<Menu.Portal>
<Menu.Positioner>
Expand Down

0 comments on commit be07bd6

Please sign in to comment.