jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.19k stars 6.46k forks source link

[Bug]: mocking modules does not seem to work? #15351

Open patrick99e99 opened 4 hours ago

patrick99e99 commented 4 hours ago

Version

29.7.0

Steps to reproduce

  1. clone repo: https://github.com/patrick99e99/jest-mock-test
  2. npm i
  3. npm run test

Expected behavior

3 tests passing

Actual behavior

Nothing works.. mocking the module for ./my-class.js

  1. an export foo is added, it is not there when imported
  2. MyClass is overwritten, expecting a mocked out instance with someMethod returning mocked-value but instead it is the original implementation.
  3. Attempted same thing but with a delayed import aka await import('./my-class'); .. same result.

Additional context

No response

Environment

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Max
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
  npmPackages:
    jest: ^29.7.0 => 29.7.0
patrick99e99 commented 3 hours ago

I also added the sound player example tests from https://jestjs.io/docs/es6-class-mocks

They also do not work...