-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
82 lines (65 loc) · 2.02 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
/* eslint-env mocha */
var assert = require('assert')
var buildObject = require('./')
describe('buildObject', function () {
it('should throw an error on non-arrays', function () {
assert.throws(function () { buildObject(0) }, TypeError)
assert.throws(function () { buildObject(true) }, TypeError)
assert.throws(function () { buildObject({}) }, TypeError)
})
it('should throw if the key isn\'t a string', function () {
assert.throws(function () { buildObject([[undefined]]) }, TypeError)
assert.throws(function () { buildObject([[null]]) }, TypeError)
assert.throws(function () { buildObject([[true]]) }, TypeError)
assert.throws(function () { buildObject([[{}]]) }, TypeError)
})
it('should return empty objects', function () {
assert.deepStrictEqual(buildObject(), {})
assert.deepStrictEqual(buildObject(null), {})
assert.deepStrictEqual(buildObject(undefined), {})
assert.deepStrictEqual(buildObject(''), {})
})
it('should build an empty object', function () {
assert.deepStrictEqual(buildObject([]), {})
})
it('should build a simple object', function () {
var input = [
['firstName', 'Linus'],
['lastName', 'Unnebäck']
]
var output = {
firstName: 'Linus',
lastName: 'Unnebäck'
}
assert.deepStrictEqual(buildObject(input), output)
})
it('should override earlier values', function () {
var input = [
['firstName', 'Steve'],
['firstName', 'Linus']
]
var output = {
firstName: 'Linus'
}
assert.deepStrictEqual(buildObject(input), output)
})
it('should be able to assign undefined', function () {
var input = [
['firstName', 'Linus'],
['firstName', undefined]
]
var output = {
firstName: undefined
}
assert.deepStrictEqual(buildObject(input), output)
})
it('should build object with number keys', function () {
var input = [
[0, 'test']
]
var output = {
0: 'test'
}
assert.deepStrictEqual(buildObject(input), output)
})
})