Skip to content

Commit

Permalink
fix(transformers): hoist jest.enableAutomock and jest.disableAutomock
Browse files Browse the repository at this point in the history
  • Loading branch information
mblaszczyk-atlassian committed Oct 18, 2019
1 parent 2c12e8d commit ac50bc3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
48 changes: 26 additions & 22 deletions src/transformers/hoist-jest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as hoist from './hoist-jest'
const CODE_WITH_HOISTING = `
const foo = 'foo'
console.log(foo)
jest.enableAutomock()
jest.disableAutomock()
jest.mock('./foo')
jest.mock('./foo/bar', () => 'bar')
const func = () => {
Expand Down Expand Up @@ -42,27 +44,29 @@ describe('hoisting', () => {
it('should hoist jest mock() and unmock() statements', () => {
const out = transpile(CODE_WITH_HOISTING)
expect(out.outputText).toMatchInlineSnapshot(`
"jest.mock('./foo');
jest.mock('./foo/bar', function () { return 'bar'; });
var foo = 'foo';
console.log(foo);
var func = function () {
jest.unmock('./foo');
jest.mock('./bar');
jest.mock('./bar/foo', function () { return 'foo'; });
jest.unmock('./foo/bar');
var bar = 'bar';
console.log(bar);
};
var func2 = function () {
jest.mock('./bar');
jest.unmock('./foo/bar');
jest.mock('./bar/foo', function () { return 'foo'; });
jest.unmock('./foo');
var bar = 'bar';
console.log(bar);
};
"
`)
"jest.enableAutomock();
jest.disableAutomock();
jest.mock('./foo');
jest.mock('./foo/bar', function () { return 'bar'; });
var foo = 'foo';
console.log(foo);
var func = function () {
jest.unmock('./foo');
jest.mock('./bar');
jest.mock('./bar/foo', function () { return 'foo'; });
jest.unmock('./foo/bar');
var bar = 'bar';
console.log(bar);
};
var func2 = function () {
jest.mock('./bar');
jest.unmock('./foo/bar');
jest.mock('./bar/foo', function () { return 'foo'; });
jest.unmock('./foo');
var bar = 'bar';
console.log(bar);
};
"
`)
})
})
2 changes: 1 addition & 1 deletion src/transformers/hoist-jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ConfigSet } from '../config/config-set'
/**
* What methods of `jest` should we hoist
*/
const HOIST_METHODS = ['mock', 'unmock']
const HOIST_METHODS = ['mock', 'unmock', 'enableAutomock', 'disableAutomock']

/**
* @internal
Expand Down

0 comments on commit ac50bc3

Please sign in to comment.