Skip to content

Commit ac50bc3

Browse files
fix(transformers): hoist jest.enableAutomock and jest.disableAutomock
1 parent 2c12e8d commit ac50bc3

2 files changed

Lines changed: 27 additions & 23 deletions

File tree

src/transformers/hoist-jest.spec.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as hoist from './hoist-jest'
66
const CODE_WITH_HOISTING = `
77
const foo = 'foo'
88
console.log(foo)
9+
jest.enableAutomock()
10+
jest.disableAutomock()
911
jest.mock('./foo')
1012
jest.mock('./foo/bar', () => 'bar')
1113
const func = () => {
@@ -42,27 +44,29 @@ describe('hoisting', () => {
4244
it('should hoist jest mock() and unmock() statements', () => {
4345
const out = transpile(CODE_WITH_HOISTING)
4446
expect(out.outputText).toMatchInlineSnapshot(`
45-
"jest.mock('./foo');
46-
jest.mock('./foo/bar', function () { return 'bar'; });
47-
var foo = 'foo';
48-
console.log(foo);
49-
var func = function () {
50-
jest.unmock('./foo');
51-
jest.mock('./bar');
52-
jest.mock('./bar/foo', function () { return 'foo'; });
53-
jest.unmock('./foo/bar');
54-
var bar = 'bar';
55-
console.log(bar);
56-
};
57-
var func2 = function () {
58-
jest.mock('./bar');
59-
jest.unmock('./foo/bar');
60-
jest.mock('./bar/foo', function () { return 'foo'; });
61-
jest.unmock('./foo');
62-
var bar = 'bar';
63-
console.log(bar);
64-
};
65-
"
66-
`)
47+
"jest.enableAutomock();
48+
jest.disableAutomock();
49+
jest.mock('./foo');
50+
jest.mock('./foo/bar', function () { return 'bar'; });
51+
var foo = 'foo';
52+
console.log(foo);
53+
var func = function () {
54+
jest.unmock('./foo');
55+
jest.mock('./bar');
56+
jest.mock('./bar/foo', function () { return 'foo'; });
57+
jest.unmock('./foo/bar');
58+
var bar = 'bar';
59+
console.log(bar);
60+
};
61+
var func2 = function () {
62+
jest.mock('./bar');
63+
jest.unmock('./foo/bar');
64+
jest.mock('./bar/foo', function () { return 'foo'; });
65+
jest.unmock('./foo');
66+
var bar = 'bar';
67+
console.log(bar);
68+
};
69+
"
70+
`)
6771
})
6872
})

src/transformers/hoist-jest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { ConfigSet } from '../config/config-set'
1717
/**
1818
* What methods of `jest` should we hoist
1919
*/
20-
const HOIST_METHODS = ['mock', 'unmock']
20+
const HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock']
2121

2222
/**
2323
* @internal

0 commit comments

Comments
 (0)