testing-library / testing-library/user-event

"moduleResolution": "Node16" default/named export bug

Open
#1,062 3 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs specification
Dominant language
TypeScript
Stars
2.3k
Forks
258
PR merge metrics
No merged PRs in 30d

Description

Reproduction example

Note: unable to provide a codesandbox link due to the inability to control the version of TypeScript used by the IDE

Prerequisites
  1. typescript@4.8.3
  2. @testing-library/user-event@14.4.3
  3. package.json type: module
  4. tsconfig moduleResolution set to Node16
// tsconfig
{
  "compilerOptions": {
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "Node16"
  }
}
Expected behavior

userEvent should be the default export of the module

import userEvent from "@testing-library/user-event";

userEvent.click(...);
Actual behavior

userEvent is exported as a named export called default

import userEvent from "@testing-library/user-event";

userEvent.default.click(...);
User-event version

14.4.3

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

This may be invalid for Node 16's ESM spec.

I suspect changing it to the following will resolve the issue:

import {userEvent} from './setup';
export default userEvent;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/index.ts at the linked export and compare it with the referenced ./setup module. Reproduce the default-versus-named export behavior using TypeScript 4.8.3, Node16 module resolution, and @testing-library/user-event 14.4.3; done means the documented default import exposes click directly without .default.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
frontend, testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.