Proper use of async UserEvent methods #910
-
My team was working on the upgrade from I went through and read the initial issue (#504) as well as the PRs that referenced it and it doesn't seem like there was ever a clear resolution or documentation on how they intend you use it? There was some good back and forth on proper testing methodology between the team, then the issue went dead, and finally it was implemented (somehow) without any documentation that I can find. Is the idea that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you get The real user interaction happens concurrently to any code running. The browser implements a UI on top of the DOM and this DOM is programmatically available to JS code which itself runs in the Event Loop. The concurrent real user interactions causes the browser to dispatch events as new macrotasks on the Event Loop. The asynchronous implementation allows us to push code to the Event Loop as a new micro- or macro-task so that it runs after e.g. an event handler, a render, or after we accessed an asynchronous API. |
Beta Was this translation helpful? Give feedback.
If you get
const user = userEvent.setup()
at the beginning of the test and thenawait user.anyApi()
for simulating user interaction, you probably won't need to bother what happens under the hood inuser-event
, the DOM implementation and the JS framework of your choice. I recommend@typescript-eslint/no-floating-promises
.The real user interaction happens concurrently to any code running. The browser implements a UI on top of the DOM and this DOM is programmatically available to JS code which itself runs in the Event Loop. The concurrent real user interactions causes the browser to dispatch events as new macrotasks on the Event Loop.
When a JS test runner like Jest executes JS tests which …