1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
3
- exports [` hoisting should hoist correctly jest methods 1` ] = `
3
+ exports [` hoist-jest with module CommonJS should hoist correctly when not using @jest/globals 1` ] = `
4
4
"\\ "use strict\\ ";
5
5
Object.defineProperty(exports, \\ "__esModule\\ ", { value : true } );
6
- var globals_1 = require(\\ "@jest/globals\\ ");
7
6
// These will all be hoisted above imports
8
7
jest.unmock('react');
9
8
jest.deepUnmock('../__test_modules__/Unmocked');
10
9
jest.unmock('../__test_modules__/c').unmock('../__test_modules__/d');
11
- jest.mock('../__test_modules__/f', function () {
10
+ jest.mock('../__test_modules__/f', () => {
12
11
if (! global .CALLS ) {
13
12
global.CALLS = 0;
14
13
}
15
14
global .CALLS ++ ;
16
15
return {
17
16
_isMock: true ,
18
- fn : function () {
17
+ fn : () => {
19
18
// The \`jest.mock\` transform will allow require, built-ins and globals.
20
- var path = require (' path' );
21
- var array = new Array (3 );
19
+ const path = require (' path' );
20
+ const array = new Array (3 );
22
21
array [0 ] = path .sep ;
23
- return jest .fn (function () { return array ; } );
22
+ return jest .fn (() => array );
24
23
},
25
24
};
26
25
} );
27
- jest.mock(\\ " ../__test_modules__/jestBackticks\\ " );
28
- jest.mock('virtual-module', function () { return ' kiwi' ; } , { virtual : true } );
26
+ jest.mock(\` ../__test_modules__/jestBackticks\` );
27
+ jest.mock('virtual-module', () => 'kiwi', { virtual : true } );
29
28
// This has types that should be ignored by the out-of-scope variables check.
30
- jest.mock('has-flow-types', function () { return function (props ) { return 3 ; }; } , {
29
+ jest.mock('has-flow-types', () => (props) => 3 , {
31
30
virtual : true ,
32
31
} );
33
- jest.unmock('../__test_modules__/' + 'a');
34
- jest.mock('../__test_modules__/f', function () { return MockMethods ; } );
35
- var Unmocked_1 = require(\\ "../__test_modules__/Unmocked\\ ");
36
- var Mocked_1 = require(\\ "../__test_modules__/Mocked\\ ");
37
- var a_1 = require(\\ "../__test_modules__/a\\ ");
38
- var b_1 = require(\\ "../__test_modules__/b\\ ");
39
- var c_1 = require(\\ "../__test_modules__/c\\ ");
40
- var d_1 = require(\\ "../__test_modules__/d\\ ");
41
- var jestBackticks_1 = require(\\ "../__test_modules__/jestBackticks\\ ");
32
+ jest.mock('../__test_modules__/f', () => MockMethods);
33
+ const Unmocked_1 = require(\\ "../__test_modules__/Unmocked\\ ");
34
+ const Mocked_1 = require(\\ "../__test_modules__/Mocked\\ ");
35
+ const a_1 = require(\\ "../__test_modules__/a\\ ");
36
+ const b_1 = require(\\ "../__test_modules__/b\\ ");
37
+ const c_1 = require(\\ "../__test_modules__/c\\ ");
38
+ const d_1 = require(\\ "../__test_modules__/d\\ ");
39
+ const jestBackticks_1 = require(\\ "../__test_modules__/jestBackticks\\ ");
42
40
// The virtual mock call below will be hoisted above this \` require\` call.
43
- var virtualModule = require('virtual-module');
44
- var e;
41
+ const virtualModule = require('virtual-module');
42
+ let e;
45
43
(function () {
46
44
// hoisted to the top of the function scope
47
45
jest .unmock (' ../__test_modules__/e' );
48
- var _getJestObj = 42 ;
46
+ const _getJestObj = 42 ;
49
47
e = require (' ../__test_modules__/e' ).default ;
50
48
} )();
51
49
// These will not be hoisted
52
50
jest.unmock('../__test_modules__/a').dontMock('../__test_modules__/b');
53
51
jest.dontMock('../__test_modules__/Mocked');
54
52
{
53
+ const jest = { unmock : () => { } };
55
54
// Would error (used before initialization) if hoisted to the top of the scope
56
55
jest .unmock (' ../__test_modules__/a' );
57
- var jest = { unmock : function () { } };
58
56
}
59
57
// This must not throw an error
60
- var myObject = { mock : function () { } } ;
58
+ const myObject = { mock : () => { } } ;
61
59
myObject.mock('apple', 27);
62
60
// Variable names prefixed with \` mock\` (ignore case) should not throw as out-of-scope
63
- var MockMethods = function () { } ;
61
+ const MockMethods = () => { } ;
64
62
console.log(Unmocked_1.default);
65
63
console.log(Mocked_1.default);
66
64
console.log(a_1.default);
@@ -70,33 +68,220 @@ console.log(d_1.default);
70
68
console.log(e);
71
69
console.log(virtualModule);
72
70
console.log(jestBackticks_1.default);
73
- console.log(globals_1.it);
74
71
"
75
72
` ;
76
73
77
- exports [` hoisting should hoist correctly jest methods 2 ` ] = `
74
+ exports [` hoist-jest with module CommonJS should hoist correctly when using with @jest/globals 1 ` ] = `
78
75
"\\ "use strict\\ ";
79
76
Object.defineProperty(exports, \\ "__esModule\\ ", { value : true } );
80
- var globals_1 = require(\\ "@jest/globals\\ ");
81
- var globals_2 = require(\\ "@jest/globals\\ ");
82
- var JestGlobals = require(\\ "@jest/globals\\ ");
83
- // These will be hoisted above imports
84
- globals_1.jest.unmock('../__test_modules__/a');
85
- globals_2.jest.unmock('../__test_modules__/b');
86
- JestGlobals.jest.unmock('../__test_modules__/c');
87
- var a_1 = require(\\ "../__test_modules__/a\\ ");
88
- var b_1 = require(\\ "../__test_modules__/b\\ ");
89
- var c_1 = require(\\ "../__test_modules__/c\\ ");
90
- var d_1 = require(\\ "../__test_modules__/d\\ ");
91
- // These will not be hoisted above imports
77
+ const JestGlobals = require(\\ "@jest/globals\\ ");
78
+ const globals_1 = require(\\ "@jest/globals\\ ");
79
+ const globals_2 = require(\\ "@jest/globals\\ ");
80
+ // These will all be hoisted above imports
81
+ globals_2.jest.unmock('react');
82
+ globals_1.jest.deepUnmock('../__test_modules__/Unmocked');
83
+ JestGlobals.jest.unmock('../__test_modules__/c').unmock('../__test_modules__/d');
84
+ JestGlobals.jest.mock('../__test_modules__/f', () => {
85
+ if (! global .CALLS ) {
86
+ global.CALLS = 0;
87
+ }
88
+ global .CALLS ++ ;
89
+ return {
90
+ _isMock: true ,
91
+ fn : () => {
92
+ // The \`jest.mock\` transform will allow require, built-ins and globals.
93
+ const path = require (' path' );
94
+ const array = new Array (3 );
95
+ array [0 ] = path .sep ;
96
+ return globals_2 .jest .fn (() => array );
97
+ },
98
+ };
99
+ } );
100
+ globals_1.jest.jest.mock(\` ../__test_modules__/jestBackticks\` );
101
+ globals_2.jest.mock('virtual-module', () => 'kiwi', { virtual : true } );
102
+ // This has types that should be ignored by the out-of-scope variables check.
103
+ globals_2.jest.mock('has-flow-types', () => (props) => 3, {
104
+ virtual : true ,
105
+ } );
106
+ JestGlobals.jest.mock('../__test_modules__/f', () => MockMethods);
107
+ const Unmocked_1 = require(\\ "../__test_modules__/Unmocked\\ ");
108
+ const Mocked_1 = require(\\ "../__test_modules__/Mocked\\ ");
109
+ const a_1 = require(\\ "../__test_modules__/a\\ ");
110
+ const b_1 = require(\\ "../__test_modules__/b\\ ");
111
+ const c_1 = require(\\ "../__test_modules__/c\\ ");
112
+ const d_1 = require(\\ "../__test_modules__/d\\ ");
113
+ const jestBackticks_1 = require(\\ "../__test_modules__/jestBackticks\\ ");
114
+ // The virtual mock call below will be hoisted above this \` require\` call.
115
+ const virtualModule = require('virtual-module');
116
+ let e;
117
+ (function () {
118
+ // hoisted to the top of the function scope
119
+ globals_2 .jest .unmock (' ../__test_modules__/e' );
120
+ const _getJestObj = 42 ;
121
+ e = require (' ../__test_modules__/e' ).default ;
122
+ } )();
123
+ // These will not be hoisted
124
+ globals_2.jest.unmock('../__test_modules__/a').dontMock('../__test_modules__/b');
125
+ globals_1.jest.dontMock('../__test_modules__/Mocked');
92
126
{
93
- jest_1 .unmock (' ../__test_modules__/d' );
94
- var jest_1 = { unmock : function () { } };
127
+ const jest = { unmock : () => { } };
128
+ // Would error (used before initialization) if hoisted to the top of the scope
129
+ jest .unmock (' ../__test_modules__/a' );
95
130
}
131
+ // This must not throw an error
132
+ const myObject = { mock : () => { } } ;
133
+ myObject.mock('apple', 27);
134
+ // Variable names prefixed with \` mock\` (ignore case) should not throw as out-of-scope
135
+ const MockMethods = () => { } ;
136
+ console.log(Unmocked_1.default);
137
+ console.log(Mocked_1.default);
96
138
console.log(a_1.default);
97
139
console.log(b_1.default);
98
140
console.log(c_1.default);
99
141
console.log(d_1.default);
100
- console.log(globals_1.it);
142
+ console.log(e);
143
+ console.log(virtualModule);
144
+ console.log(jestBackticks_1.default);
145
+ "
146
+ ` ;
147
+
148
+ exports [` hoist-jest with module ESM should hoist correctly when not using @jest/globals 1` ] = `
149
+ "// These will all be hoisted above imports
150
+ jest.unmock('react');
151
+ jest.deepUnmock('../__test_modules__/Unmocked');
152
+ jest.unmock('../__test_modules__/c').unmock('../__test_modules__/d');
153
+ jest.mock('../__test_modules__/f', () => {
154
+ if (! global .CALLS ) {
155
+ global.CALLS = 0;
156
+ }
157
+ global .CALLS ++ ;
158
+ return {
159
+ _isMock: true ,
160
+ fn : () => {
161
+ // The \`jest.mock\` transform will allow require, built-ins and globals.
162
+ const path = require (' path' );
163
+ const array = new Array (3 );
164
+ array [0 ] = path .sep ;
165
+ return jest .fn (() => array );
166
+ },
167
+ };
168
+ } );
169
+ jest.mock(\` ../__test_modules__/jestBackticks\` );
170
+ jest.mock('virtual-module', () => 'kiwi', { virtual : true } );
171
+ // This has types that should be ignored by the out-of-scope variables check.
172
+ jest.mock('has-flow-types', () => (props) => 3, {
173
+ virtual : true ,
174
+ } );
175
+ jest.mock('../__test_modules__/f', () => MockMethods);
176
+ import Unmocked from '../__test_modules__/Unmocked';
177
+ import Mocked from '../__test_modules__/Mocked';
178
+ import a from '../__test_modules__/a';
179
+ import b from '../__test_modules__/b';
180
+ import c from '../__test_modules__/c';
181
+ import d from '../__test_modules__/d';
182
+ import jestBackticks from '../__test_modules__/jestBackticks';
183
+ // The virtual mock call below will be hoisted above this \` require\` call.
184
+ const virtualModule = require('virtual-module');
185
+ let e;
186
+ (function () {
187
+ // hoisted to the top of the function scope
188
+ jest .unmock (' ../__test_modules__/e' );
189
+ const _getJestObj = 42 ;
190
+ e = require (' ../__test_modules__/e' ).default ;
191
+ } )();
192
+ // These will not be hoisted
193
+ jest.unmock('../__test_modules__/a').dontMock('../__test_modules__/b');
194
+ jest.dontMock('../__test_modules__/Mocked');
195
+ {
196
+ const jest = { unmock : () => { } };
197
+ // Would error (used before initialization) if hoisted to the top of the scope
198
+ jest .unmock (' ../__test_modules__/a' );
199
+ }
200
+ // This must not throw an error
201
+ const myObject = { mock : () => { } } ;
202
+ myObject.mock('apple', 27);
203
+ // Variable names prefixed with \` mock\` (ignore case) should not throw as out-of-scope
204
+ const MockMethods = () => { } ;
205
+ console.log(Unmocked);
206
+ console.log(Mocked);
207
+ console.log(a);
208
+ console.log(b);
209
+ console.log(c);
210
+ console.log(d);
211
+ console.log(e);
212
+ console.log(virtualModule);
213
+ console.log(jestBackticks);
214
+ "
215
+ ` ;
216
+
217
+ exports [` hoist-jest with module ESM should hoist correctly when using with @jest/globals 1` ] = `
218
+ "import * as JestGlobals from '@jest/globals';
219
+ import { jest as aliasedJest } from '@jest/globals';
220
+ import { jest } from '@jest/globals';
221
+ // These will all be hoisted above imports
222
+ jest.unmock('react');
223
+ aliasedJest.deepUnmock('../__test_modules__/Unmocked');
224
+ JestGlobals.jest.unmock('../__test_modules__/c').unmock('../__test_modules__/d');
225
+ JestGlobals.jest.mock('../__test_modules__/f', () => {
226
+ if (! global .CALLS ) {
227
+ global.CALLS = 0;
228
+ }
229
+ global .CALLS ++ ;
230
+ return {
231
+ _isMock: true ,
232
+ fn : () => {
233
+ // The \`jest.mock\` transform will allow require, built-ins and globals.
234
+ const path = require (' path' );
235
+ const array = new Array (3 );
236
+ array [0 ] = path .sep ;
237
+ return jest .fn (() => array );
238
+ },
239
+ };
240
+ } );
241
+ aliasedJest.jest.mock(\` ../__test_modules__/jestBackticks\` );
242
+ jest.mock('virtual-module', () => 'kiwi', { virtual : true } );
243
+ // This has types that should be ignored by the out-of-scope variables check.
244
+ jest.mock('has-flow-types', () => (props) => 3, {
245
+ virtual : true ,
246
+ } );
247
+ JestGlobals.jest.mock('../__test_modules__/f', () => MockMethods);
248
+ import Unmocked from '../__test_modules__/Unmocked';
249
+ import Mocked from '../__test_modules__/Mocked';
250
+ import a from '../__test_modules__/a';
251
+ import b from '../__test_modules__/b';
252
+ import c from '../__test_modules__/c';
253
+ import d from '../__test_modules__/d';
254
+ import jestBackticks from '../__test_modules__/jestBackticks';
255
+ // The virtual mock call below will be hoisted above this \` require\` call.
256
+ const virtualModule = require('virtual-module');
257
+ let e;
258
+ (function () {
259
+ // hoisted to the top of the function scope
260
+ jest .unmock (' ../__test_modules__/e' );
261
+ const _getJestObj = 42 ;
262
+ e = require (' ../__test_modules__/e' ).default ;
263
+ } )();
264
+ // These will not be hoisted
265
+ jest.unmock('../__test_modules__/a').dontMock('../__test_modules__/b');
266
+ aliasedJest.dontMock('../__test_modules__/Mocked');
267
+ {
268
+ const jest = { unmock : () => { } };
269
+ // Would error (used before initialization) if hoisted to the top of the scope
270
+ jest .unmock (' ../__test_modules__/a' );
271
+ }
272
+ // This must not throw an error
273
+ const myObject = { mock : () => { } } ;
274
+ myObject.mock('apple', 27);
275
+ // Variable names prefixed with \` mock\` (ignore case) should not throw as out-of-scope
276
+ const MockMethods = () => { } ;
277
+ console.log(Unmocked);
278
+ console.log(Mocked);
279
+ console.log(a);
280
+ console.log(b);
281
+ console.log(c);
282
+ console.log(d);
283
+ console.log(e);
284
+ console.log(virtualModule);
285
+ console.log(jestBackticks);
101
286
"
102
287
` ;
0 commit comments