question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

activeElement might change during userEvent.type causing runtime errors

See original GitHub issue
  • @testing-library/user-event version: >= 11.1.0
  • @testing-library/dom version: 5.10.1
  • Testing Framework and version: jest@26.0.1
  • DOM Environment: jsdom jest-environment-jsdom-global@2.0.2
  • node: 13.7.0

What you did:

Using userEvent.type. We have like > 1k tests which mostly use fireEvent but slowly upgrading to userEvent. All run fine, execept for one I encountered while updating our dependencies.

As a tmp fix one can use fireEvent.change.

What happened:

I narrowed it down to start with the release of https://github.com/testing-library/user-event/releases/tag/v11.1.0

    TypeError: Cannot read property 'length' of undefined

      at calculateNewValue (node_modules/@testing-library/user-event/dist/type.js:312:43)
      at typeCharacter (node_modules/@testing-library/user-event/dist/type.js:366:43)
      at typeImpl (node_modules/@testing-library/user-event/dist/type.js:230:29)
      at node_modules/@testing-library/user-event/dist/type.js:20:14
      at node_modules/@testing-library/react/dist/pure.js:58:16

Reproduction:

Problem description:

We currently have 90 occurrences for await userEvent.type( in our codebase, yet only a single one has this issue. I don’t understand (yet) what could cause this. But I figured out the activeElement is always the body, so calling currentValue() will be undefined, as body has no value prop.

I will provide more details if I find more.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
Junhao6503commented, Sep 16, 2020

I am still encountering this issue due to portals. It gives me errors like:

TypeError: Cannot read property 'length' of undefined
      at setSelectionRange (node_modules/@testing-library/user-event/dist/type.js:240:70)
      at fireInputEventIfNeeded (node_modules/@testing-library/user-event/dist/type.js:269:5)
      at handleDel (node_modules/@testing-library/user-event/dist/type.js:613:5)
      at node_modules/@testing-library/user-event/dist/type.js:144:29
      at typeImpl (node_modules/@testing-library/user-event/dist/type.js:159:4)
      at type (node_modules/@testing-library/user-event/dist/type.js:73:14)
      at Object.clear (node_modules/@testing-library/user-event/dist/clear.js:26:18)
      at Object.<anonymous> (src/__tests__/UserProfile/UserProfileEdit.test.js:148:17)
1reaction
tsmithATXcommented, Jul 30, 2020

v12.0.14 addressed our issues, no longer seeing this happen!

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Testing Library - testing in isolation and userEvent error
I noticed that element.ownerDocument.activeElement is null wasAnotherElementFocused is true and so it throws the error. The first time I run the ...
Read more >
user-event v13 - Testing Library
Fires a tab event changing the document.activeElement in the same way the browser does. Options: shift (default false ) can be true or...
Read more >
5. SMIL 3.0 Timing and Synchronization - W3C
A document containing SMIL Timing and Synchronization elements and attributes is referred to as a host document. As this module is used in...
Read more >
JavaScript - Royal Icing
We can do this by running requestAnimationFrame() ourself. However, when testing React we need to ensure anything that could change state is ...
Read more >
Bug List - Bugzilla - allizom.org
ID Summary Product Comp Assigne... 1352852 "dragstart" requires setting dataTransfer Core DOM: Events nobody 1480664 'mouseout' event fires prematurely for element Core DOM: Events nobody 1493530...
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