-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
matchers-toStrictEqual.property.test.ts
77 lines (73 loc) · 1.89 KB
/
matchers-toStrictEqual.property.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
/**
* 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 assert from 'assert';
import {onNodeVersions} from '@jest/test-utils';
import fc from 'fast-check';
import expect from '..';
import {
anythingSettings,
assertSettings,
} from './__arbitraries__/sharedSettings';
describe('toStrictEqual', () => {
const safeExpectStrictEqual = (a, b) => {
try {
expect(a).toStrictEqual(b);
return true;
} catch {
return false;
}
};
const safeAssertDeepStrictEqual = (a, b) => {
try {
assert.deepStrictEqual(a, b);
return true;
} catch {
return false;
}
};
it('should be reflexive', () => {
fc.assert(
fc.property(fc.dedup(fc.anything(anythingSettings), 2), ([a, b]) => {
// Given: a and b identical values
expect(a).toStrictEqual(b);
}),
assertSettings,
);
});
it('should be symmetric', () => {
fc.assert(
fc.property(
fc.anything(anythingSettings),
fc.anything(anythingSettings),
(a, b) => {
// Given: a and b values
// Assert: We expect `expect(a).toStrictEqual(b)`
// to be equivalent to `expect(b).toStrictEqual(a)`
expect(safeExpectStrictEqual(a, b)).toBe(safeExpectStrictEqual(b, a));
},
),
assertSettings,
);
});
onNodeVersions('>=9', () => {
it('should be equivalent to Node deepStrictEqual', () => {
fc.assert(
fc.property(
fc.anything(anythingSettings),
fc.anything(anythingSettings),
(a, b) => {
expect(safeExpectStrictEqual(a, b)).toBe(
safeAssertDeepStrictEqual(a, b),
);
},
),
assertSettings,
);
});
});
});