File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+
46export { useAppContext } from '../test/test-utils.jsx' ;
57export default vi . fn ( ) ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments