forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 3
/
importJest.test.js
53 lines (42 loc) 路 1.33 KB
/
importJest.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
/* eslint-disable import/no-duplicates */
import {jest} from '@jest/globals';
import {jest as aliasedJest} from '@jest/globals';
import * as JestGlobals from '@jest/globals';
/* eslint-enable import/no-duplicates */
import a from '../__test_modules__/a';
import b from '../__test_modules__/b';
import c from '../__test_modules__/c';
import d from '../__test_modules__/d';
// These will be hoisted above imports
jest.unmock('../__test_modules__/a');
aliasedJest.unmock('../__test_modules__/b');
JestGlobals.jest.unmock('../__test_modules__/c');
// These will not be hoisted above imports
{
const jest = {unmock: () => {}};
jest.unmock('../__test_modules__/d');
}
// tests
test('named import', () => {
expect(a._isMockFunction).toBe(undefined);
expect(a()).toBe('unmocked');
});
test('aliased named import', () => {
expect(b._isMockFunction).toBe(undefined);
expect(b()).toBe('unmocked');
});
test('namespace import', () => {
expect(c._isMockFunction).toBe(undefined);
expect(c()).toBe('unmocked');
});
test('fake jest, shadowed import', () => {
expect(d._isMockFunction).toBe(true);
expect(d()).toBe(undefined);
});