Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tchock committed Dec 18, 2024
1 parent 28fa1d1 commit d646b98
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
7 changes: 2 additions & 5 deletions src/Portal/Portal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import {
render,
getByTestId as globalGetByTestId,
getAllByTestId as globalGetAllByTestId,
waitFor,
} from '@testing-library/react';
import React from 'react';
import { PabloThemeProvider, rootContext } from '../theme';
import { PabloThemeProvider } from '../theme';
import { Portal } from './Portal';

test('Render Portal component', () => {
Expand Down Expand Up @@ -34,7 +33,7 @@ test('Forward ref object with ShadowRoot', async () => {
renderComponent({ ref }, shadowRoot);
expect(ref.current).toBeDefined();
expect(ref.current.getAttribute('data-testid')).toBe('pbl-portal-mountpoint');
expect(ref.current.parentElement).toBe(shadowRoot);
expect(ref.current.parentNode).toBe(shadowRoot);
});

test('Forward ref function with ShadowRoot', () => {
Expand All @@ -46,8 +45,6 @@ test('Forward ref function with ShadowRoot', () => {
});

function renderComponent(props: object, rootElement: ShadowRoot | Document = document) {
console.log('document', rootElement);

const { baseElement, unmount } = render(
<PabloThemeProvider root={rootElement}>
<Portal name="portal" {...props}>
Expand Down
6 changes: 0 additions & 6 deletions src/Portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ export const Portal = forwardRef<unknown, PortalProps>(({ children, name }, ref)
if (mountPoint) {
mountPoint.setAttribute('data-testid', `pbl-${name}-mountpoint`);
const mountPointParent = rootElement instanceof ShadowRoot ? rootElement : rootElement.body;

console.log('Appending mountPoint to:', mountPointParent);
mountPointParent.appendChild(mountPoint);
setRef(ref, mountPoint);
setTimeout(() => {
console.log('mountPointParent', mountPointParent, mountPoint.parentElement);
});
return () => {
console.log('Removing mountPoint from:', mountPointParent);
mountPointParent.removeChild(mountPoint);
};
}
Expand Down

0 comments on commit d646b98

Please sign in to comment.