TypeError: textRange(...).getClientRects is not a function

Got this error from automated tests. It happened only once, after an edit of an unrelated markdown file.

TypeError: textRange(...).getClientRects is not a function
 ❯ clientRectsFor node_modules/@codemirror/view/dist/index.js:37:56
     35| function clientRectsFor(dom) {
     36|     if (dom.nodeType == 3)
     37|         return textRange(dom, 0, dom.nodeValue.length).getClientRects(…
       |                                                        ^
     38|     else if (dom.nodeType == 1)
     39|         return dom.getClientRects();
 ❯ LineView.measureTextSize node_modules/@codemirror/view/dist/index.js:1565:25
 ❯ DocView.measureTextSize node_modules/@codemirror/view/dist/index.js:3212:37
 ❯ ViewState.measure node_modules/@codemirror/view/dist/index.js:6083:74
 ❯ EditorView.measure node_modules/@codemirror/view/dist/index.js:7827:46
 ❯ node_modules/@codemirror/view/dist/index.js:7978:79
 ❯ invokeTheCallbackFunction node_modules/jsdom/lib/jsdom/living/generated/Function.js:19:26
 ❯ runAnimationFrameCallbacks node_modules/jsdom/lib/jsdom/browser/Window.js:688:13
 ❯ Timeout.<anonymous> node_modules/jsdom/lib/jsdom/browser/Window.js:666:11
 ❯ listOnTimeout node:internal/timers:581:17

This error originated in "src/components/Editor.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running.
The latest test that might've caused the error is "handles selectedLine prop for scrolling". It might mean one of the following:
- The error was thrown, while Vitest was running this test.
- If the error occurred after the test had been completed, this was the last documented test before it was thrown.

This is the project:

In the code I have a jump to particular line:

const { from: position } = doc.line(line);
viewRef.current.dispatch({
  selection: { anchor: position, head: position },
  scrollIntoView: true
});

This is ReactJS project and ref contain the Editor instance. I use React wrapper: @uiw/react-codemirror

The question is why this is happening and if this is a bug in CodeMirror? I would not like to have flaky tests.

Here is example of broken test:

Note: it shows a wrong icon, but the test failed with exception.

Found the solution in jsDOM:

For an unknown reason, the tests were working fine locally.

Right. The editor view isn’t supported under jsDOM. You may get it to work, but I don’t provide any guaranteed.