Skip to content

[Bug]: conflicting expect extensions break jest-config #11977

@blaky

Description

@blaky

Version

27.3.0

Steps to reproduce

In my project we are in the process of migrating tests from enzyme to testing-library, currently we have both of them in the project while we migrate the tests on a one-by-one basis. Both of these libraries define the toBeChecked (and many other duplicated expect extension). Before #11949 we were able to control which of these should take precedence by setting the order of imports. The PR mentioned above changed the code so it is now uses Object.defineProperty to add extensions to the expect object without the configurable property set.

Clone my repo: https://github.com/blaky/jest-issue
npm ci
npm test

The error you'll see:

 ● Test suite failed to run

    TypeError: Cannot redefine property: toBeChecked
        at Function.defineProperty (<anonymous>)

      at node_modules/expect/build/jestMatchersObject.js:103:14
          at Array.forEach (<anonymous>)

Expected behavior

Jest doesn't fail when loading expect extensions with conflicting names.

Actual behavior

Jest fails when loading expect extensions with conflicting names.

Additional context

No response

Environment

System:
    OS: macOS 11.5.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
  Binaries:
    Node: 14.17.4 - ~/.nvm/versions/node/v14.17.4/bin/node
    npm: 6.14.14 - ~/.nvm/versions/node/v14.17.4/bin/npm
  npmPackages:
    jest: ^27.3.0 => 27.3.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions