-
Notifications
You must be signed in to change notification settings - Fork 0
/
chaimel.test.js
62 lines (60 loc) · 1.99 KB
/
chaimel.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
var expect = require('./')
function willThrow () {
throw new Error()
}
describe('the chaimel assertion extensions', function () {
[
[42, 'toEqual', 42],
[42, 'notToEqual', 43],
[42, 'toEqual', 42],
[42, 'toBeAbove', 41],
[42, 'toBeGreaterThan', 41],
[42, 'notToBeAbove', 43],
['abc', 'toInclude', 'b'],
['abc', 'toMatch', /b/],
[false, 'toBeFalse'],
[true, 'toBeTrue'],
[arguments, 'toBeArguments'],
[[1, 2, 3], 'toHaveLengthOfAtMost', 3],
[[1, 2, 3], 'toHaveLengthWithin', 2, 4],
[[1, 2, 3], 'toHaveLength', 3],
[{foo: {bar: [42]}}, 'toHaveDeepProperty', 'foo.bar[0]'],
[42, 'toBeWithin', 41, 43],
[[], 'toBeInstanceof', Array],
[[], 'toBeInstanceOf', Array],
[[], 'toBeAnInstanceOf', Array],
['', 'toBeA', 'string'],
[{}, 'toBeAn', 'object'],
[[], 'toBeAnInstanceof', Array],
[{foo: 1, bar: 2}, 'toHaveKeys', 'foo', 'bar'],
[willThrow, 'toThrow', Error],
[[{id: 1}], 'toHaveDeepMembers', [{id: 1}]],
[{id: 1}, 'toHaveProperty', 'id', 1],
[null, 'toBeNull'],
[42, 'notToBeNull'],
[42, 'toBeOk'],
[void 0, 'toBeUndefined'],
[42, 'toExist'],
[void 0, 'notToExist']
].forEach(function (set) {
it('should support ' + set[1], function () {
var assert = expect(set[0])
assert[set[1]].apply(assert, set.slice(2))
})
})
it('should support chaining to thatIsA', function () {
expect({id: 1}).toHaveProperty('id').thatIsA('number')
})
it('should support chaining to thatIsAn', function () {
expect({list: []}).toHaveProperty('list').thatIsAn('array')
})
it('should support chaining to thatIsGreaterThan', function () {
expect({id: 1}).toHaveProperty('id').thatIsGreaterThan(0)
})
it('should support chaining to thatIsAnInstanceOf', function () {
expect({list: [1, 2]}).toHaveProperty('list').thatIsAnInstanceOf(Array)
})
it('should support chaining to thatIsNotBelow', function () {
expect({count: 9}).toHaveProperty('count').thatIsNotBelow(8)
})
})