Skip to content

Commit

Permalink
Fix Popper-related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Feb 27, 2024
1 parent d004404 commit 26d835a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 7 additions & 1 deletion packages/mui-base/src/Menu/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import { Popper } from '@mui/base/Popper';
import { MenuProvider, useMenu } from '@mui/base/useMenu';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

function createAnchor() {
const anchor = document.createElement('div');
document.body.appendChild(anchor);
return anchor;
}

const testContext: DropdownContextValue = {
dispatch: () => {},
popupId: 'menu-popup',
Expand Down Expand Up @@ -158,7 +164,7 @@ describe('<Menu />', () => {
disabledItemsFocusable: false,
});

const anchorEl = triggerElement ?? document.createElement('div');
const anchorEl = triggerElement ?? createAnchor();

return (
<Popper open={open} anchorEl={anchorEl}>
Expand Down
16 changes: 8 additions & 8 deletions packages/mui-base/src/Popper/Popper.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import { createRenderer, createMount, screen } from '@mui/internal-test-utils';
import { Popper, popperClasses } from '@mui/base/Popper';
import { describeConformanceUnstyled } from '../../test/describeConformanceUnstyled';

function createAnchor() {
const anchor = document.createElement('div');
document.body.appendChild(anchor);
return anchor;
}

describe('<Popper />', () => {
const { render } = createRenderer();
const mount = createMount();

const defaultProps = {
anchorEl: () => document.createElement('svg'),
anchorEl: () => createAnchor(),
children: <span>Hello World</span>,
open: true,
};
Expand All @@ -35,13 +41,7 @@ describe('<Popper />', () => {
const CustomComponent = React.forwardRef<HTMLDivElement, any>(({ ownerState }, ref) => (
<div ref={ref} data-testid="foo" id={ownerState.id} />
));
render(
<Popper
anchorEl={() => document.createElement('div')}
open
slots={{ root: CustomComponent }}
/>,
);
render(<Popper anchorEl={() => createAnchor()} open slots={{ root: CustomComponent }} />);

expect(screen.getByTestId('foo')).to.not.have.attribute('id', 'id');
});
Expand Down
8 changes: 7 additions & 1 deletion packages/mui-base/src/Unstable_Popup/Popup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { describeConformanceUnstyled } from '../../test/describeConformanceUnsty

const TRANSITION_DURATION = 100;

function createAnchor() {
const anchor = document.createElement('div');
document.body.appendChild(anchor);
return anchor;
}

function FakeTransition(props: React.PropsWithChildren<{}>) {
const { children: transitionChildren } = props;
const { requestedEnter, onExited } = useTransitionStateManager();
Expand Down Expand Up @@ -45,7 +51,7 @@ describe('<Popup />', () => {
}

const defaultProps: PopupProps = {
anchor: () => document.createElement('div'),
anchor: () => createAnchor(),
children: <span>Hello World</span>,
open: true,
};
Expand Down

0 comments on commit 26d835a

Please sign in to comment.