Skip to content

Commit

Permalink
[test] Add the isJSDOM utility (mui#1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak authored Jan 8, 2025
1 parent 9552903 commit 24301b6
Show file tree
Hide file tree
Showing 36 changed files with 79 additions and 116 deletions.
4 changes: 1 addition & 3 deletions packages/react/src/accordion/root/AccordionRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { spy } from 'sinon';
import { flushMicrotasks } from '@mui/internal-test-utils';
import { DirectionProvider } from '@base-ui-components/react/direction-provider';
import { Accordion } from '@base-ui-components/react/accordion';
import { createRenderer, describeConformance } from '#test-utils';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';

const PANEL_CONTENT_1 = 'Panel contents 1';
const PANEL_CONTENT_2 = 'Panel contents 2';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import * as React from 'react';
import { expect } from 'chai';
import { screen, waitFor } from '@mui/internal-test-utils';
import { AlertDialog } from '@base-ui-components/react/alert-dialog';
import { createRenderer } from '#test-utils';
import { createRenderer, isJSDOM } from '#test-utils';
import { spy } from 'sinon';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

describe('<AlertDialog.Root />', () => {
const { render } = createRenderer();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { expect } from 'chai';
import { Checkbox } from '@base-ui-components/react/checkbox';
import { createRenderer, describeConformance } from '#test-utils';
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';
import { screen, waitFor } from '@mui/internal-test-utils';
import { CheckboxRootContext } from '../root/CheckboxRootContext';

Expand Down Expand Up @@ -98,7 +98,7 @@ describe('<Checkbox.Indicator />', () => {
});

it('should remove the indicator when there is no exit animation defined', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -128,7 +128,7 @@ describe('<Checkbox.Indicator />', () => {
});

it('should remove the indicator when the animation finishes', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/checkbox/root/CheckboxRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { act, fireEvent } from '@mui/internal-test-utils';
import { Checkbox } from '@base-ui-components/react/checkbox';
import { createRenderer, describeConformance } from '#test-utils';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';

describe('<Checkbox.Root />', () => {
const { render } = createRenderer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { act, fireEvent, flushMicrotasks } from '@mui/internal-test-utils';
import { Collapsible } from '@base-ui-components/react/collapsible';
import { createRenderer, describeConformance } from '#test-utils';
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';
import { NOOP } from '../../utils/noop';
import { CollapsibleRootContext } from '../root/CollapsibleRootContext';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

const PANEL_CONTENT = 'This is panel content';

const contextValue: CollapsibleRootContext = {
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/collapsible/root/CollapsibleRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import * as React from 'react';
import { expect } from 'chai';
import { flushMicrotasks } from '@mui/internal-test-utils';
import { Collapsible } from '@base-ui-components/react/collapsible';
import { createRenderer, describeConformance } from '#test-utils';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';

const PANEL_CONTENT = 'This is panel content';

Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/composite/root/CompositeRoot.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as React from 'react';
import { expect } from 'chai';
import { act, createRenderer, fireEvent, flushMicrotasks } from '@mui/internal-test-utils';
import { isJSDOM } from '#test-utils';
import { CompositeItem } from '../item/CompositeItem';
import { CompositeRoot } from './CompositeRoot';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

describe('Composite', () => {
const { render } = createRenderer();

Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/dialog/popup/DialogPopup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { expect } from 'chai';
import { Dialog } from '@base-ui-components/react/dialog';
import { AlertDialog } from '@base-ui-components/react/alert-dialog';
import { act, waitFor, screen } from '@mui/internal-test-utils';
import { describeConformance, createRenderer } from '#test-utils';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);
import { describeConformance, createRenderer, isJSDOM } from '#test-utils';

describe('<Dialog.Popup />', () => {
const { render } = createRenderer();
Expand Down
10 changes: 4 additions & 6 deletions packages/react/src/dialog/root/DialogRoot.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { act, fireEvent, screen, waitFor } from '@mui/internal-test-utils';
import { Dialog } from '@base-ui-components/react/dialog';
import { createRenderer } from '#test-utils';
import { createRenderer, isJSDOM } from '#test-utils';
import { Menu } from '@base-ui-components/react/menu';
import { Select } from '@base-ui-components/react/select';

const isJSDOM = /jsdom/.test(window.navigator.userAgent);

describe('<Dialog.Root />', () => {
beforeEach(() => {
globalThis.BASE_UI_ANIMATIONS_DISABLED = true;
Expand Down Expand Up @@ -58,7 +56,7 @@ describe('<Dialog.Root />', () => {
});

it('should remove the popup when there is no exit animation defined', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -88,7 +86,7 @@ describe('<Dialog.Root />', () => {
});

it('should remove the popup when the animation finishes', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -380,7 +378,7 @@ describe('<Dialog.Root />', () => {
}
`;

if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Menu } from '@base-ui-components/react/menu';
import { createRenderer, describeConformance } from '#test-utils';
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';
import { screen, waitFor } from '@mui/internal-test-utils';
import { expect } from 'chai';

Expand Down Expand Up @@ -29,7 +29,7 @@ describe('<Menu.CheckboxItemIndicator />', () => {
}));

it('should remove the indicator when there is no exit animation defined', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -67,7 +67,7 @@ describe('<Menu.CheckboxItemIndicator />', () => {
});

it('should remove the indicator when the animation finishes', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { fireEvent, act, waitFor } from '@mui/internal-test-utils';
import { Menu } from '@base-ui-components/react/menu';
import { describeConformance, createRenderer } from '../../../test';
import { describeConformance, createRenderer, isJSDOM } from '#test-utils';

describe('<Menu.CheckboxItem />', () => {
const { render, clock } = createRenderer({
Expand All @@ -22,7 +22,7 @@ describe('<Menu.CheckboxItem />', () => {
}));

it('perf: does not rerender menu items unnecessarily', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -191,7 +191,7 @@ describe('<Menu.CheckboxItem />', () => {
});

it(`toggles the checked state when Enter is pressed`, async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/menu/item/MenuItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { spy } from 'sinon';
import { MemoryRouter, Route, Routes, Link, useLocation } from 'react-router-dom';
import { act, screen, waitFor } from '@mui/internal-test-utils';
import { Menu } from '@base-ui-components/react/menu';
import { describeConformance, createRenderer } from '#test-utils';
import { describeConformance, createRenderer, isJSDOM } from '#test-utils';

describe('<Menu.Item />', () => {
const { render, clock } = createRenderer({
Expand Down Expand Up @@ -45,7 +45,7 @@ describe('<Menu.Item />', () => {
});

it('perf: does not rerender menu items unnecessarily', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/menu/positioner/MenuPositioner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from 'chai';
import userEvent from '@testing-library/user-event';
import { flushMicrotasks } from '@mui/internal-test-utils';
import { Menu } from '@base-ui-components/react/menu';
import { describeConformance, createRenderer } from '#test-utils';
import { describeConformance, createRenderer, isJSDOM } from '#test-utils';

describe('<Menu.Positioner />', () => {
const { render } = createRenderer();
Expand All @@ -21,7 +21,7 @@ describe('<Menu.Positioner />', () => {

describe('prop: anchor', () => {
it('should be placed near the specified element when a ref is passed', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -68,7 +68,7 @@ describe('<Menu.Positioner />', () => {
it('should be placed near the specified element when an element is passed', async ({
skip,
}) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -118,7 +118,7 @@ describe('<Menu.Positioner />', () => {
it('should be placed near the specified element when a function returning an element is passed', async ({
skip,
}) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -168,7 +168,7 @@ describe('<Menu.Positioner />', () => {
});

it('should be placed at the specified position', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { Menu } from '@base-ui-components/react/menu';
import { createRenderer, describeConformance } from '#test-utils';
import { createRenderer, describeConformance, isJSDOM } from '#test-utils';
import { screen, waitFor } from '@mui/internal-test-utils';
import { expect } from 'chai';

Expand All @@ -27,7 +27,7 @@ describe('<Menu.RadioItemIndicator />', () => {
}));

it('should remove the indicator when there is no exit animation defined', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down Expand Up @@ -72,7 +72,7 @@ describe('<Menu.RadioItemIndicator />', () => {
});

it('should remove the indicator when the animation finishes', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/menu/radio-item/MenuRadioItem.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { expect } from 'chai';
import { spy } from 'sinon';
import { fireEvent, act, waitFor } from '@mui/internal-test-utils';
import { Menu } from '@base-ui-components/react/menu';
import { describeConformance, createRenderer } from '#test-utils';
import { describeConformance, createRenderer, isJSDOM } from '#test-utils';
import { MenuRadioGroupContext } from '../radio-group/MenuRadioGroupContext';

const testRadioGroupContext = {
Expand Down Expand Up @@ -34,7 +34,7 @@ describe('<Menu.RadioItem />', () => {
}));

it('perf: does not rerender menu items unnecessarily', async ({ skip }) => {
if (/jsdom/.test(window.navigator.userAgent)) {
if (isJSDOM) {
skip();
}

Expand Down
Loading

0 comments on commit 24301b6

Please sign in to comment.