-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
109 lines (93 loc) · 3.86 KB
/
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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var chai = require('chai')
var chaiAlmost = require('./index')
chai.use(chaiAlmost())
var expect = chai.expect
describe('chaiAlmost', function () {
describe('almost method', function () {
describe('with shallow equality', function () {
it('should modify shallow equality checks on numbers to allow default tolerance', function () {
expect(3.9999999).to.be.almost(4)
expect(3.9).not.to.be.almost(4)
})
it('should modify shallow equality checks on numbers to allow custom tolerance', function () {
expect(3.8).to.be.almost(4, 1)
expect(2).not.to.be.almost(4, 1)
})
it('should not modify shallow equality checks on non-numbers', function () {
expect('taco').to.be.almost('taco')
expect('taco').to.not.be.almost('tacos')
var x = { taco: 'pastor' }
var y = [1, 2, 3]
expect(x).to.be.almost(x)
expect(x).to.not.be.almost({ taco: 'pastor' })
expect(y).to.be.almost(y)
expect(y).to.not.be.almost([1, 2, 3])
})
})
describe('with deep equality', function () {
it('should modify deep equality checks to allow default tolerance for numbers', function () {
var exp = { taco: 'pastor', quantity: 3 }
var good = { taco: 'pastor', quantity: 2.9999999 }
var bad = { taco: 'pastor', quantity: 3.1 }
expect(good).to.be.deep.almost(exp)
expect(bad).to.not.be.deep.almost(exp)
})
it('should modify deep equality checks to allow custom tolerance for numbers', function () {
var exp = { taco: 'pastor', quantity: 10 }
var good = { taco: 'pastor', quantity: 29 }
var bad = { taco: 'pastor', quantity: 31 }
expect(good).to.be.deep.almost(exp, 20)
expect(bad).to.not.be.deep.almost(exp, 20)
})
})
})
describe('almost chainable method', function () {
describe('with shallow equality', function () {
it('should modify shallow equality checks on numbers to allow default tolerance', function () {
var exp = 4
var good = 3.9999999
var bad = 3.9
expect(good).to.almost.equal(exp)
expect(good).to.almost.eq(exp)
expect(good).almost.equals(exp)
expect(bad).to.not.almost.equal(exp)
expect(bad).to.not.almost.eq(exp)
expect(bad).not.almost.equals(exp)
})
it('should not modify shallow equality checks on non-numbers', function () {
expect('taco').to.almost.equal('taco')
expect('taco').to.not.almost.equal('tacos')
var x = { taco: 'pastor' }
var y = [1, 2, 3]
expect(x).to.almost.equal(x)
expect(x).to.not.almost.equal({ taco: 'pastor' })
expect(y).to.almost.equal(y)
expect(y).to.not.almost.equal([1, 2, 3])
})
})
describe('with deep equality', function () {
it('should modify deep equality checks to allow default tolerance for numbers', function () {
var exp = { taco: 'pastor', quantity: 3 }
var good = { taco: 'pastor', quantity: 2.9999999 }
var bad = { taco: 'pastor', quantity: 3.1 }
expect(good).to.almost.eql(exp)
expect(good).to.deep.almost.equal(exp)
expect(good).almost.deep.eqls(exp)
expect(bad).to.not.almost.eql(exp)
expect(bad).to.not.deep.almost.equal(exp)
expect(bad).not.almost.deep.eqls(exp)
})
it('should not modify shallow equality checks on non-numbers', function () {
var exp = { taco: 'pastor', delicious: true }
var good = { taco: 'pastor', delicious: true }
var bad = { taco: 'pastor', delicious: false }
expect(good).to.almost.eql(exp)
expect(good).to.deep.almost.equal(exp)
expect(good).almost.deep.eqls(exp)
expect(bad).to.not.almost.eql(exp)
expect(bad).to.not.deep.almost.equal(exp)
expect(bad).not.almost.deep.eqls(exp)
})
})
})
})