jestjs/jest

[Bug]: createMockFromModule not mocking class correctly

Open

#14.178 aperta il 2 giu 2023

Vedi su GitHub
 (9 commenti) (0 reazioni) (0 assegnatari)TypeScript (6653 fork)batch import
:bug: BugHelp WantedPinned

Metriche repository

Star
 (45.361 star)
Metriche merge PR
 (Merge medio 11g 22h) (11 PR mergiate in 30 g)

Descrizione

Version

29.5.0

Steps to reproduce

  1. Clone my repo at https://github.com/dominiktopp/jestCreateMockFromModuleIssue
  2. npm install
  3. npm test
  4. tests will fail

Expected behavior

I expect the test cases to succeed.

Actual behavior

Tests are failing because jest.createMockFromModule only mocks constructor and functions for classes but no other properties (also no getters). The example for jest.createMockFromModule does not mock an exported class but an instance of a class: class: new (class Bar {...})()

Additional context

No response

Environment

System:
  OS: Windows 10 10.0.19045
  CPU: (12) x64 Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
  Memory: 10.67 GB / 31.76 GB
Binaries:
  Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
  npm: 8.5.5 - C:\Program Files\nodejs\npm.CMD

Guida contributor