You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The different tests mock a function from a module in a different way. All of them as per documentation. However none of them seem to be working.
Expected behavior
The mocked function should be mocked, making the tests pass and it's real implementation not executed, as a result of the mocking.
Actual behavior
None of the mocks work. The actual implementation of the mocked function runs and none of the expects calls are passing.
Additional context
I've tried different suggestions from different posts on StackOverflow but none seem to work. There is no transpilation in this setup.
The only thing that worked was changing all the call-sites to reference the fully exported function - i.e. instead of calling myFunctionToMock() I'd have to call module.exports.myFunctionToMock().
Version
29.7.0
Steps to reproduce
npm test
The different tests mock a function from a module in a different way. All of them as per documentation. However none of them seem to be working.
Expected behavior
The mocked function should be mocked, making the tests pass and it's real implementation not executed, as a result of the mocking.
Actual behavior
None of the mocks work. The actual implementation of the mocked function runs and none of the
expect
s calls are passing.Additional context
I've tried different suggestions from different posts on StackOverflow but none seem to work. There is no transpilation in this setup.
The only thing that worked was changing all the call-sites to reference the fully exported function - i.e. instead of calling
myFunctionToMock()
I'd have to callmodule.exports.myFunctionToMock()
.Environment
System: OS: macOS 14.4.1 CPU: (10) arm64 Apple M1 Max Binaries: Node: 21.6.2 - /opt/homebrew/bin/node Yarn: 1.22.21 - /opt/homebrew/bin/yarn npm: 10.2.4 - /opt/homebrew/bin/npm npmPackages: jest: ^29.7.0 => 29.7.0
The text was updated successfully, but these errors were encountered: