Skip to content

Commit

Permalink
Fix test failure due to BodyPortal
Browse files Browse the repository at this point in the history
  • Loading branch information
Dantemss committed Jan 23, 2025
1 parent cff63a8 commit 89bed03
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/app/content/highlights/components/Card.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import DisplayNote from './DisplayNote';
import EditCard from './EditCard';
import showConfirmation from './utils/showConfirmation';
import { ConfirmationToastProvider } from '../../components/ConfirmationToast';
import ReactDOM from 'react-dom';

jest.mock('./DisplayNote', () => (jest as any).requireActual('react').forwardRef(
(props: any, ref: any) => <div ref={ref} mock-display-note {...props} />
Expand All @@ -48,6 +49,12 @@ describe('Card', () => {
let highlightData: ReturnType<ReturnType<typeof createMockHighlight>['serialize']>['data'];
let cardProps: Partial<CardProps> & { highlight: Highlight };
let createNodeMock: () => HTMLElement;
let createPortalMock: jest.Mock<React.ReactPortal, [elt: React.ReactNode]>;

beforeAll(() => {
createPortalMock = jest.fn((elt) => elt as React.ReactPortal);
ReactDOM.createPortal = createPortalMock;
});

beforeEach(() => {
store = createTestStore();
Expand All @@ -64,6 +71,10 @@ describe('Card', () => {
createNodeMock = () => assertDocument().createElement('div');
});

afterEach(() => {
createPortalMock.mockClear();
});

it('matches snapshot when focused without note', () => {
highlight.range.getBoundingClientRect.mockReturnValue({
bottom: 200,
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/highlights/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function NoteOrCard({
showToast({
message: 'Highlight removed',
});
}
}
}, [locationFilterId, props, showToast, setHighlightRemoved]);
const style = highlightStyles.find(
search => props.data && search.label === props.data.color
Expand Down

0 comments on commit 89bed03

Please sign in to comment.