Skip to content

Duplicate fireEvent export creates Rollup warnings #790

Closed
@FredKSchott

Description

@FredKSchott
  • @testing-library/react version: latest
  • Testing Framework and version: n/a
  • DOM Environment: n/a

Relevant code or config:

https://github.com/testing-library/react-testing-library/blob/master/src/pure.js#L118-L120

// just re-export everything from dom-testing-library
export * from '@testing-library/dom'
export {render, cleanup, act, fireEvent}

What you did:

Bundled this package with Rollup via Snowpack.

What happened:

[snowpack] Conflicting namespaces: ../../node_modules/@testing-library/react/dist/@testing-library/react.esm.js re-exports 'fireEvent' from both ../../node_modules/@testing-library/react/dist/@testing-library/react.esm.js and ../../node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js (will be ignored)

Problem description:

fireEvent is exported twice out of the @testing-library/react package: once directly, and then once indirectly via an export * invocation (see link above). This is invalid ESM that will break in pure ESM environments (ex: Node) and create warnings in others (Snowpack, Rollup, etc). See convo below.

Suggested solution:

Ref: https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

  1. Stop re-exporting @testing-library/dom, let the user import things out of this package themselves as needed.
  2. re-export an explicit set of named exports. Harder to maintain.
  3. export the custom package fireEvent function as fireReactEvent instead, preventing conflict.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions