forked from nan-ci/beta-01-E01
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
93 lines (92 loc) · 2.66 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
const getSize = exports => Object.keys(exports)
.filter(key => !key.includes(' '))
.length
module.exports = ({ stringify, describe, test, code, exports }) => [
describe('str', test.prop('str', String, '42')),
describe('num', test.prop('num', Number, 42)),
describe('bool', test.prop('bool', Boolean, false)),
describe('escapeStr', [
test.defined('escapeStr'),
test.type('escapeStr', String),
].concat('\\\'"`'.split('').map(c =>
test(`should contain the character ${c}`)
.value(exports.escapeStr)
.include(c)))),
describe('spaced key', [
test(`module.exports['spaced key'] should equal true`)
.value(exports)
.map('spaced key')
.equal(true)
,
]),
describe('arr', [
test.defined('arr'),
test.type('arr', Array),
test('should have 2 elements')
.value(exports.arr)
.map('length')
.equal(2)
,
test('first element should be 4')
.value(exports.arr)
.map('0')
.equal(4)
,
test('second element should be \'2\'')
.value(exports.arr)
.map('1')
.equal('2')
,
]),
describe('fn', [
test.defined('fn'),
test.type('fn', Function),
test('should take 1 argument')
.value(exports.fn)
.map('length')
.equal(1)
,
].concat([ 5, 'pouet', { lol: 'xD' }, Symbol() ]
.map(val => ({ val, key: stringify(val) }))
.map(({ val, key }) =>
test(`calling function fn with argument ${key} should return ${key}`)
.value(exports.fn)
.map(fn => fn(val))
.equal(val, `fn(${key}) === ${key}`)))),
describe('get', [
test.defined('get'),
test.type('get', Function),
test('should take 1 argument')
.value(exports.get)
.map('length')
.equal(1)
,
].concat([ 'str', 'bool', 'num', 'arr', 'fn', 'get', '42' ].map(key =>
test(`calling function get with argument '${key
}' should return ${stringify(exports[key])}`)
.value(exports.get)
.map(get => get(key))
.deepEqual(exports[key],
`get(${stringify(key)}) === ${stringify(exports[key])}`)))),
describe('obj', [
test.defined('obj'),
test.type('obj', Object),
test(`should have ${getSize(exports)} elements`)
.value(exports.obj)
.map(Object.keys)
.map('length')
.equal(getSize(exports))
,
].concat(Object.keys(exports).filter(key => !key.includes(' '))
.map(key => test(`obj.${key} should equal module.exports.${key}`)
.value(exports.obj)
.map(key)
.deepEqual(exports[key])))
.concat([
test('obj.obj should be a circular reference and equal itself')
.value(exports.obj)
.map('obj')
.equal(exports.obj)
,
])),
]