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] jest.mock([moduleName]) not working with custom resolver specified #4985

Closed
gwyneplaine opened this issue Nov 29, 2017 · 4 comments
Closed

Comments

@gwyneplaine
Copy link

gwyneplaine commented Nov 29, 2017

Do you want to request a feature or report a bug?
Bug

What is the current behavior?

Calling jest.mock([moduleName]) on an external module does not automatically mock the methods, but instead returns the actual methods within that module.

What is the expected behavior?

Calling jest.mock([moduleName]) on an external module should automatically mock out the methods in that module.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

This bug occurs in [email protected] and above, and does not occur in older versions of Jest.
I am running:

  • node v8.4.0
  • yarn 1.3.2
  • mac osx

Please find an example of this bug illustrated in a repo found here.

This issue seems to be related to the following PR #4174 from @midzelis and merged by @cpojer and is a result of the following lines of code

Removing this block of code resolves this issue. I'm happy to open a PR for this, should it be the correct fix.

@gwyneplaine gwyneplaine changed the title jest.mock([moduleName]) not working with custom resolver specified [BUG] jest.mock([moduleName]) not working with custom resolver specified Nov 30, 2017
@Thinkscape
Copy link

This makes Jest 21+ unusable for our project and we're stuck with v20.

Basically the auto jest.mock() functionality is not working at all; our existing tests started throwing things like i.e.:

Exception has occurred: TypeError
TypeError: module.someMethod.mockReturnValueOnce is not a function

@dlmr
Copy link
Contributor

dlmr commented Jan 22, 2018

Any suggestions on how to address this issue, would be happy to create a PR but not sure what the correct approach is here.

Do anyone have examples on what this code path is supposed to do and why removing it would be the wrong solution?

@SimenB
Copy link
Member

SimenB commented Jan 28, 2018

I'm not really sure what's wrong here. There was a similar bugfix to normal mock in #4489, maybe that can serve as inspiration?

A failing test is also a great contribution, might be easier for others to jump in and help if there's already a test for it 🙂

arcanis pushed a commit to arcanis/jest that referenced this issue Apr 19, 2018
arcanis pushed a commit to arcanis/jest that referenced this issue Apr 19, 2018
@cpojer cpojer closed this as completed in 0722a1e Apr 20, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants