forked from jestjs/jest
/
expectationResultFactory.test.ts
93 lines (85 loc) · 2.7 KB
/
expectationResultFactory.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* 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 expectationResultFactory from '../expectationResultFactory';
describe('expectationResultFactory', () => {
it('returns the result if passed.', () => {
const options = {
matcherName: 'testMatcher',
passed: true,
};
const result = expectationResultFactory(options);
expect(result).toMatchSnapshot();
});
it('returns the result if failed.', () => {
const options = {
actual: 'Fail',
expected: 'Pass',
matcherName: 'testMatcher',
passed: false,
};
const result = expectationResultFactory(options);
expect(result.message).toEqual('thrown: undefined');
});
it('returns the result if failed (with `message`).', () => {
const message = 'This message is not "Expected `Pass`, received `Fail`."';
const options = {
actual: 'Fail',
error: new Error('This will be ignored in `message`.'),
expected: 'Pass',
matcherName: 'testMatcher',
message,
passed: false,
};
const result = expectationResultFactory(options);
expect(result.message).toEqual(message);
});
it('returns the result if failed (with `error`).', () => {
const options = {
actual: 'Fail',
error: new Error('Expected `Pass`, received `Fail`.'),
expected: 'Pass',
matcherName: 'testMatcher',
passed: false,
};
const result = expectationResultFactory(options);
expect(result.message).toEqual('Error: Expected `Pass`, received `Fail`.');
});
it('returns the error name if the error message is empty', () => {
const options = {
actual: 'Fail',
error: new Error(),
expected: 'Pass',
matcherName: 'testMatcher',
passed: false,
};
const result = expectationResultFactory(options);
expect(result.message).toEqual('Error');
});
it('returns the result if failed (with `error` as a string).', () => {
const options = {
actual: 'Fail',
error: 'Expected `Pass`, received `Fail`.',
expected: 'Pass',
matcherName: 'testMatcher',
passed: false,
};
const result = expectationResultFactory(options);
expect(result.message).toEqual('Expected `Pass`, received `Fail`.');
});
it('returns the result if failed (with `error.stack` not as a string).', () => {
const options = {
actual: 'Fail',
error: {stack: 42},
expected: 'Pass',
matcherName: 'testMatcher',
passed: false,
};
const result = expectationResultFactory(options);
expect(result.message).toMatchSnapshot();
});
});