Skip to content

Does deepUnmock only work with require? #1746

@MicheleBertoli

Description

@MicheleBertoli

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;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions