timkindberg / jest-when

Jest support for mock argument-matched return values.
MIT License
737 stars 39 forks source link

Cannot find module 'expect/build/jasmineUtils' from 'node_modules/jest-when/src/when.js' #87

Closed voda closed 3 years ago

voda commented 3 years ago

Hi, after updating to the latest version our tests are failing on:

  ● Test suite failed to run

    Cannot find module 'expect/build/jasmineUtils' from 'node_modules/jest-when/src/when.js'

    Require stack:
      node_modules/jest-when/src/when.js
      some.test.ts

      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
      at Object.<anonymous> (node_modules/jest-when/src/when.js:2:15)

If I understand it correctly it is related to https://github.com/timkindberg/jest-when/pull/84 and expect package.

In our project, we don't have any expect package directly in node_modules, only in subfolders.

$ npm ls expect
├─┬ jest@26.6.3
│ └─┬ @jest/core@26.6.3
│   ├─┬ jest-config@26.6.3
│   │ └─┬ jest-jasmine2@26.6.3
│   │   └── expect@26.6.2 
│   ├─┬ jest-runtime@26.6.3
│   │ └─┬ @jest/globals@26.6.2
│   │   └── expect@26.6.2 
│   └─┬ jest-snapshot@26.6.2
│     └── expect@26.6.2 
└─┬ snapshot-diff@0.9.0
  └─┬ jest-snapshot@27.1.0
    └── expect@27.1.0

Any ideas on how to best fix it? I was not able to replicate this in a fresh project.

I guess one solution could be convincing npm to install one expect version directly to node_modules.

timkindberg commented 3 years ago

Fixed via v3.4.1

voda commented 3 years ago

Confirmed the fix works. Thank you for this library.