-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjestExpectExtend.test.js
52 lines (48 loc) · 1.14 KB
/
jestExpectExtend.test.js
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
const Matrix = require('./lib/matrix');
describe('jest expect shallowEpsilonEquals', () => {
test('shallowEpsilonEquals equals', () => {
const o1 = {
a: 0.1 + 0.2,
};
const o2 = {
a: 0.3,
};
expect(o1).shallowEpsilonEquals(o2);
});
test('shallowEpsilonEquals not equals', () => {
const o1 = {
a: 0.1 + 0.2,
};
const o2 = {
a: 0.301,
};
expect(o1).not.shallowEpsilonEquals(o2);
});
test('shallowEpsilonEquals failure', () => {
expect.assertions(3);
const o1 = {
a: 0.1 + 0.2,
};
const o2 = {
a: 0.4,
};
try {
expect(o1).shallowEpsilonEquals(o2);
} catch (e) {
expect(e.message).toContain(0.3000000000);
expect(e.matcherResult.pass).toBe(false);
}
});
test('matrixEquals failure', () => {
expect.assertions(4);
const m1 = new Matrix(2, 2, [1, 2, 3, 4]);
const m2 = new Matrix(2, 2, [1, 2, 3, 6]);
try {
expect(m1).matrixEquals(m2);
} catch (e) {
expect(e.message).toContain(4.00000);
expect(e.message).toContain(6.00000);
expect(e.matcherResult.pass).toBe(false);
}
});
});