Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Mocking function from module doesn't seem to be working #15068

Open
takecare opened this issue May 13, 2024 · 0 comments
Open

[Bug]: Mocking function from module doesn't seem to be working #15068

takecare opened this issue May 13, 2024 · 0 comments

Comments

@takecare
Copy link

Version

29.7.0

Steps to reproduce

  1. Check the tests here
  2. Run them with npm test
  3. Observe as none of them pass

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().

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant