/
testEnvironment.test.ts
64 lines (51 loc) · 1.62 KB
/
testEnvironment.test.ts
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
54
55
56
57
58
59
60
61
62
63
64
/**
* 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.
*/
import {tmpdir} from 'os';
import * as path from 'path';
import slash = require('slash');
import {cleanup, createEmptyPackage, writeFiles} from '../Utils';
import runJest, {json as runWithJson} from '../runJest';
import * as testFixturePackage from '../test-environment/package.json';
const DIR = path.resolve(tmpdir(), 'test-env-no-mocked');
beforeEach(() => cleanup(DIR));
afterAll(() => cleanup(DIR));
it('respects testEnvironment docblock', () => {
expect(testFixturePackage.jest.testEnvironment).toEqual('node');
const {json: result} = runWithJson('test-environment');
expect(result.success).toBe(true);
expect(result.numTotalTests).toBe(4);
});
it('handles missing `mocked` property', () => {
createEmptyPackage(DIR);
writeFiles(DIR, {
'env.js': `
const Node = require('${slash(
require.resolve('jest-environment-node'),
)}').default;
module.exports = class Thing extends Node {
constructor(...args) {
super(...args);
this.moduleMocker.mocked = undefined;
}
};
`,
'test.js': `
/**
* @jest-environment ./env.js
*/
jest.mocked();
test('halla', () => {
expect(globalThis.thing).toBe('nope');
});
`,
});
const {exitCode, stderr} = runJest(DIR);
expect(exitCode).toBe(1);
expect(stderr).toContain(
'Your test environment does not support `mocked`, please update it.',
);
});