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

Does deepUnmock only work with require? #1746

Closed
MicheleBertoli opened this issue Sep 20, 2016 · 2 comments
Closed

Does deepUnmock only work with require? #1746

MicheleBertoli opened this issue Sep 20, 2016 · 2 comments
Assignees
Milestone

Comments

@MicheleBertoli
Copy link
Contributor

MicheleBertoli commented Sep 20, 2016

Hello! Thanks for your amazing work with the new version of Jest.

I know that the deepUnmock function is not documented (yet?) but I was following #1188 and I would really love to use it.

However, I found out that it works only with require and it doesn't with modules (unless there's something wrong with the following code).

Is there a reason for that? Can I apply a workaround or something?

Config

"jest": {
  "automock": true
}

ES5 😻

// ./__tests__/test.js

jest.deepUnmock('../src/sum-1');

var sum = require('../src/sum-1');

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});
// ./src/sum-1.js

var sum = require('./sum-2');

module.exports = sum
// ./src/sum-2.js

function sum(a, b) {
  return a + b;
}

module.exports = sum

ES2015 😿

// ./__tests__/test.js

jest.deepUnmock('../src/sum-1');

import sum from '../src/sum-1';

test('adds 1 + 2 to equal 3', () => {
  expect(sum(1, 2)).toBe(3);
});
// ./src/sum-1.js

import sum from './sum-2';

export default sum;
// ./src/sum-2.js

function sum(a, b) {
  return a + b;
}

export default sum;
@cpojer
Copy link
Member

cpojer commented Sep 21, 2016

This is indeed a bug. Will be fixed in Jest 16.

@cpojer cpojer closed this as completed Sep 21, 2016
@cpojer cpojer added this to the 16.0.0 milestone Sep 21, 2016
@cpojer cpojer self-assigned this Sep 21, 2016
@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 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants