Skip to content

Commit 92f6723

Browse files
Copilotpayamnj
andauthored
fix: explicit vi import in render mock; patch Text/Range.getClientRects for ProseMirror
Agent-Logs-Url: https://github.com/AvaCodeSolutions/django-email-learning/sessions/441cafc3-06cd-4339-aade-0b3dd794af20 Co-authored-by: payamnj <11951509+payamnj@users.noreply.github.com>
1 parent 43886ae commit 92f6723

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

frontend/src/__mocks__/render.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Manual mock for src/render.jsx
22
// Re-exports useAppContext backed by the test AppContext so components
33
// rendered via renderWithProviders(…) receive the correct context values.
4+
import { vi } from 'vitest';
5+
46
export { useAppContext } from '../test/test-utils.jsx';
57
export default vi.fn();

frontend/src/test/setup.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ beforeEach(() => {
6161
global.fetch.mockResolvedValue({ ok: true, json: () => Promise.resolve({}) });
6262
});
6363

64-
// ProseMirror calls Element.getClientRects() when scrolling to selection.
65-
// jsdom does not implement this method, which causes unhandled errors during
66-
// ContentEditor tests. Provide a minimal stub so ProseMirror exits cleanly.
67-
Element.prototype.getClientRects = vi.fn(() => []);
64+
// ProseMirror's scroll-to-selection requires getClientRects / getBoundingClientRect
65+
// on Text nodes and Range objects — neither is implemented by jsdom.
66+
// Provide minimal stubs so the EditorView exits cleanly instead of throwing.
67+
const _emptyRects = [];
68+
if (typeof Text !== 'undefined') {
69+
Text.prototype.getClientRects = vi.fn(() => _emptyRects);
70+
Text.prototype.getBoundingClientRect = vi.fn(() => new DOMRect(0, 0, 0, 0));
71+
}
72+
if (typeof Range !== 'undefined' && !Range.prototype.getClientRects) {
73+
Range.prototype.getClientRects = vi.fn(() => _emptyRects);
74+
}
75+
// Also patch Element in case jsdom's own stub is absent in some test envs
76+
Element.prototype.getClientRects = vi.fn(() => _emptyRects);

0 commit comments

Comments
 (0)