-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
87 lines (65 loc) · 4.19 KB
/
test.js
File metadata and controls
87 lines (65 loc) · 4.19 KB
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
'usa strict'
let chai = require('chai')
let expect = chai.expect
let ObjHandler = require('./index.js')
describe('.getKeys()', () => {
it('gets the keys of an object in a list, with dot notation', (done) => {
let objectToGetKeysOf = { someString: "Certainly a string.", horse: true, potion: 1, obby: { deeper: true, deepness: { stophere: true } } }
let objectKeys = []
ObjHandler.getKeys(objectToGetKeysOf, null, objectKeys)
let expectedKeys = ['someString', 'horse', 'potion', 'obby', 'obby.deeper', 'obby.deepness', 'obby.deepness.stophere']
expect(objectKeys).to.be.an('array').to.include.members(expectedKeys)
done()
})
it('does not contain any unexpected nonsense', (done) => {
let objectToGetKeysOf = { someString: "Certainly a string.", horse: true, potion: 1, obby: { deeper: true, deepness: { stophere: true } } }
let objectKeys = []
ObjHandler.getKeys(objectToGetKeysOf, null, objectKeys)
let expectedKeys = ['sanityCheck', 'thisIsNotAProp', 'logistics', 'key.property', 'this', 1]
expect(objectKeys).to.be.an('array').to.not.include.members(expectedKeys)
done()
})
it('ensures that if you pass it something other than an object, it dies', (done) => {
let nonObjectToGetKeysOf = 12345
expect(function () { ObjHandler.getKeys(nonObjectToGetKeysOf, null, []); }).to.throw(Error, 'Item to check must be an object.')
done()
})
it('ensures that if you pass it nothing, it dies', (done) => {
expect(ObjHandler.getKeys).to.throw(Error, 'Item to check must be an object.')
done()
})
})
describe('.hasRequiredKeys()', () => {
it('ensures that the required keys exist in the object', (done) => {
let objectToGetKeysOf = { someString: "Certainly a string.", horse: true, potion: 1, obby: { deeper: true, deepness: { stophere: false, evenDeeper: { wow: 'that is deep', right: { nope: 'we can go deeper' } } } } }
let expectedKeys = ['someString', 'horse', 'potion', 'obby', 'obby.deeper', 'obby.deepness', 'obby.deepness.stophere', 'obby.deepness.evenDeeper', 'obby.deepness.evenDeeper.right.nope']
let hasKeys = ObjHandler.hasRequiredProperties(objectToGetKeysOf, expectedKeys)
expect(hasKeys).to.be.true
done()
})
it('ensures that if required keys are missing, the result is clear', (done) => {
let objectToGetKeysOf = { someString: "Certainly a string.", horse: true, potion: 1, obby: { deeper: true, deepness: { stophere: false, evenDeeper: { wow: 'that is deep', right: { nope: 'we can go deeper' } } } } }
let expectedKeys = ['someString', 'horse', 'potion', 'obby', 'obby.deeper', 'obby.deepness', 'obby.deepness.stophere', 'whyAskWhy.drinkBudDry']
let hasKeys = ObjHandler.hasRequiredProperties(objectToGetKeysOf, expectedKeys)
expect(hasKeys).to.be.false
done()
})
it('ensures that if you pass it no required keys, it returns true', (done) => {
let objectToGetKeysOf = { someString: "Certainly a string.", horse: true, potion: 1, obby: { deeper: true, deepness: { stophere: false, evenDeeper: { wow: 'that is deep', right: { nope: 'we can go deeper' } } } } }
let expectedKeys = []
let hasKeys = ObjHandler.hasRequiredProperties(objectToGetKeysOf, expectedKeys)
expect(hasKeys).to.be.true
done()
})
it('ensures that if you pass it something other than an object, it dies', (done) => {
let nonObjectToGetKeysOf = 12345
let expectedKeys = ['someString', 'horse', 'potion', 'obby', 'obby.deeper', 'obby.deepness', 'obby.deepness.stophere', 'whyAskWhy.drinkBudDry']
//let hasKeys = ObjHandler.hasRequiredKeys(nonObjectToGetKeysOf, expectedKeys)
expect(function () { ObjHandler.hasRequiredProperties(nonObjectToGetKeysOf, expectedKeys); }).to.throw(Error, 'Item to check must be an object.')
done()
})
it('ensures that if you pass it nothing, it dies', (done) => {
expect(ObjHandler.hasRequiredProperties).to.throw(Error, 'Item to check must be an object.')
done()
})
})