5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
- import { json as runWithJson } from '../runJest' ;
8
+ import { tmpdir } from 'os' ;
9
+ import * as path from 'path' ;
10
+ import slash = require( 'slash' ) ;
11
+ import { cleanup , createEmptyPackage , writeFiles } from '../Utils' ;
12
+ import runJest , { json as runWithJson } from '../runJest' ;
9
13
import * as testFixturePackage from '../test-environment/package.json' ;
10
14
15
+ const DIR = path . resolve ( tmpdir ( ) , 'test-env-no-mocked' ) ;
16
+
17
+ beforeEach ( ( ) => cleanup ( DIR ) ) ;
18
+ afterAll ( ( ) => cleanup ( DIR ) ) ;
19
+
11
20
it ( 'respects testEnvironment docblock' , ( ) => {
12
21
expect ( testFixturePackage . jest . testEnvironment ) . toEqual ( 'node' ) ;
13
22
@@ -16,3 +25,40 @@ it('respects testEnvironment docblock', () => {
16
25
expect ( result . success ) . toBe ( true ) ;
17
26
expect ( result . numTotalTests ) . toBe ( 3 ) ;
18
27
} ) ;
28
+
29
+ it ( 'handles missing `mocked` property' , ( ) => {
30
+ createEmptyPackage ( DIR ) ;
31
+ writeFiles ( DIR , {
32
+ 'env.js' : `
33
+ const Node = require('${ slash (
34
+ require . resolve ( 'jest-environment-node' ) ,
35
+ ) } ');
36
+
37
+ module.exports = class Thing extends Node {
38
+ constructor(...args) {
39
+ super(...args);
40
+
41
+ this.moduleMocker.mocked = undefined;
42
+ }
43
+ };
44
+ ` ,
45
+ 'test.js' : `
46
+ /**
47
+ * @jest-environment ./env.js
48
+ */
49
+
50
+ jest.mocked();
51
+
52
+ test('halla', () => {
53
+ expect(global.thing).toBe('nope');
54
+ });
55
+ ` ,
56
+ } ) ;
57
+
58
+ const { exitCode, stderr} = runJest ( DIR ) ;
59
+
60
+ expect ( exitCode ) . toBe ( 1 ) ;
61
+ expect ( stderr ) . toContain (
62
+ 'Your test environment does not support `mocked`, please update it.' ,
63
+ ) ;
64
+ } ) ;
0 commit comments