Skip to content

Conversation

Janpot
Copy link

@Janpot Janpot commented Aug 8, 2025

What

I noticed this in a setup where a jsdom instance was recreated for each test and globals were reassigned, userEvent used an outdated version of the global document.

Why

It's fixable by calling userEvent.setup({ document }) every time, but this PR makes that unnecessary.

How

Use a function to obtain default values, this makes it capture globalThis.document at the time userEvent.setup() is called.

Checklist

  • [N/A] Documentation: Bug fix
  • [N/A] Tests: Feels too challenging to test under the current setup. I've added a clarifying comment. Feel free to give directions otherwise.
  • Ready to be merged : Yes, if tests pass

*/
const defaultOptionsDirect: Required<Options> = {
const getDefaultOptionsDirect = (): Required<Options> => ({
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also do:

Suggested change
const getDefaultOptionsDirect = (): Required<Options> => ({
const getDefaultOptions = (overrides: Options): Required<Options> => ({

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant