10000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When using Codemirror 6 I get the following error when mocking any user event: TypeError: textRange(...).getClientRects is not a function
TypeError: textRange(...).getClientRects is not a function
I managed to fix it by adding the following code to my test file:
document.createRange = () => { const range = new Range(); range.getClientRects = () => ({ item: () => null, length: 0, [Symbol.iterator]: function *() { yield* []; }, }); return range; };
I later on found a better fix which covers more functions:
function getBoundingClientRect(): DOMRect { const rec = { x: 0, y: 0, bottom: 0, height: 0, left: 0, right: 0, top: 0, width: 0, }; return {...rec, toJSON: () => rec}; } class FakeDOMRectList extends Array<DOMRect> implements DOMRectList { item(index: number): DOMRect | null { return this[index]; } } document.elementFromPoint = (): null => null; HTMLElement.prototype.getBoundingClientRect = getBoundingClientRect; HTMLElement.prototype.getClientRects = (): DOMRectList => new FakeDOMRectList(); Range.prototype.getBoundingClientRect = getBoundingClientRect; Range.prototype.getClientRects = (): DOMRectList => new FakeDOMRectList();
This doesnt cause issues in the browser as this is JS native code.
Would be great if this implmenetation (or something simiar) can be added so that there will be no need to add hacky solutions directly to test files.
Thanks!
The text was updated successfully, but these errors were encountered:
I am also experiencing this issue. Thanks a lot @danieldongit for sharing your solution!
Sorry, something went wrong.
Successfully merging a pull request may close this issue.
Basic info:
Minimal reproduction case
When using Codemirror 6 I get the following error when mocking any user event:
TypeError: textRange(...).getClientRects is not a function
I managed to fix it by adding the following code to my test file:
I later on found a better fix which covers more functions:
How does similar code behave in browsers?
This doesnt cause issues in the browser as this is JS native code.
Would be great if this implmenetation (or something simiar) can be added so that there will be no need to add hacky solutions directly to test files.
Thanks!
The text was updated successfully, but these errors were encountered: