TypeError: range.cloneRange is not a function after updating to v.14

See original GitHub issue

Reproduction example

https://pastecode.io/s/n6p0zq9q

Prerequisites

  1. Update to user-event v.14
  2. Add async/await for tests with user-event usage.
  3. Run test

Expected behavior

Test should pass - it did with v.13.

Actual behavior

Test fails with TypeError: range.cloneRange is not a function

TypeError: range.cloneRange is not a function

  at mousedownDefaultBehavior (../../node_modules/@testing-library/user-event/dist/index.cjs:2441:32)
  at down (../../node_modules/@testing-library/user-event/dist/index.cjs:2309:7)
  at pointerPress (../../node_modules/@testing-library/user-event/dist/index.cjs:2248:19)
  at pointerAction (../../node_modules/@testing-library/user-event/dist/index.cjs:2471:33)

User-event version

14.0.4

Environment

Testing Library framework:

"@testing-library/dom": "8.12.0",
"testing-library/jest-dom": "5.16.3",
"@testing-library/react": "12.1.4",
"@testing-library/react-hooks": "7.0.2",
"@testing-library/user-event": "14.0.4",

JS framework: react@17.0.2

Test environment: jest@27.5.1

Additional context

node v.12

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

15reactions
MarijNefkenscommented, Apr 8, 2022

I ran into the same problem.

In my case the problem was not that the environment didn’t implement Range.cloneRange() but the fact that I was overwriting it in my local test setup (global.document.createRange = () => ({ ... })), which was some code from before my test environment implemented Range. Removing that from my setup fixed the issue for me.

5reactions
osamajandalicommented, Apr 11, 2022

I am having the same issue but with createRange

      TypeError: target.ownerDocument.createRange is not a function
      at mousedownDefaultBehavior (node_modules/@testing-library/user-event/dist/index.cjs:2450:42)
      at down (node_modules/@testing-library/user-event/dist/index.cjs:2324:7)
      at pointerPress (node_modules/@testing-library/user-event/dist/index.cjs:2263:19)
      at pointerAction (node_modules/@testing-library/user-event/dist/index.cjs:2486:33)
      at node_modules/@testing-library/react/dist/pure.js:59:16
Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors when updating @testing-library/user-event to v.14
TypeError : range.cloneRange is not a function. All my tests were passing before the library updates, now all failing.
Read more >
Range.cloneRange() - Web APIs - MDN Web Docs
The Range.cloneRange() method returns a Range object with boundary points identical to the cloned Range.
Read more >
UNPKG - @testing-library/user-event
1, var __defProp = Object.defineProperty;. 2, var __defProps = Object.defineProperties;. 3, var __getOwnPropDescs = Object.getOwnPropertyDescriptors;.
Read more >
DOM Standard
When dispatched in a tree, invoking this method prevents event from reaching any objects other than the current object. ✓MDN.
Read more >
Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError - Some selector is not a function - jQuery is not a function - owlCarousel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found