forked from jestjs/jest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock_names.test.js
More file actions
67 lines (50 loc) · 2 KB
/
mock_names.test.js
File metadata and controls
67 lines (50 loc) · 2 KB
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
65
66
67
/**
* Copyright (c) 2014-present, Facebook, Inc. 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.
*
* @flow
*/
'use strict';
const runJest = require('../runJest');
test('suite without mock name, mock called', () => {
const {stderr, status} = runJest('mock-names/without-mock-name');
expect(status).toBe(0);
expect(stderr).toMatch(/PASS/);
});
test('suite without mock name, mock not called', () => {
const {stderr, status} = runJest('mock-names/without-mock-name-not-called');
expect(status).toBe(1);
expect(stderr).toMatch(/expect\(jest\.fn\(\)\)\.toHaveBeenCalled/);
});
test('suite with mock name, expect mock not called', () => {
const {stderr, status} = runJest('mock-names/with-mock-name-not-called-pass');
expect(status).toBe(0);
expect(stderr).toMatch(/PASS/);
});
test('suite with mock name, mock called, expect fail', () => {
const {stderr, status} = runJest('mock-names/with-mock-name-not-called-fail');
expect(status).toBe(1);
expect(stderr).toMatch(/expect\(myMockedFunction\)\.not\.toHaveBeenCalled/);
});
test('suite with mock name, mock called 5 times', () => {
const {stderr, status} = runJest('mock-names/with-mock-name-call-times-pass');
expect(status).toBe(0);
expect(stderr).toMatch(/PASS/);
});
test('suite with mock name, mock not called 5 times, expect fail', () => {
const {stderr, status} = runJest('mock-names/with-mock-name-call-times-fail');
expect(status).toBe(1);
expect(stderr).toMatch(/expect\(myMockedFunction\)\.toHaveBeenCalledTimes/);
});
test('suite with mock name, mock called', () => {
const {stderr, status} = runJest('mock-names/with-mock-name');
expect(status).toBe(0);
expect(stderr).toMatch(/PASS/);
});
test('suite with mock name, mock not called', () => {
const {stderr, status} = runJest('mock-names/with-mock-name-not-called');
expect(status).toBe(1);
expect(stderr).toMatch(/expect\(myMockedFunction\)\.toHaveBeenCalled/);
});