-
Notifications
You must be signed in to change notification settings - Fork 24
/
constructor.js
115 lines (102 loc) · 3.05 KB
/
constructor.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
110
111
112
113
114
115
'use strict'
//----------------------------------------------------------
// Modules
//----------------------------------------------------------
// NPM
const assert = require('chai').assert
const clone = require('lodash.clonedeep')
const faker = require('faker')
const logUpdate = require('log-update')
// Local
const Multispinner = require('../../')
const Spinners = require('lib/spinners')
const defaultProps = require('lib/constants').defaultProps
const genSpinners = require('../utils/genSpinners')
//----------------------------------------------------------
// Tests
//----------------------------------------------------------
module.exports = describe('constructor', () => {
const spinners = genSpinners.arr(3)
it('Clone default props', () => {
const m = new Multispinner(spinners)
Object.keys(defaultProps).map(prop => {
assert.deepEqual(defaultProps[prop], m[prop])
})
})
it('Merge opts into props', () => {
const opts = {
clear: true,
frames: ['v', '<', '^', '>'],
indent: 4,
postText: faker.fake('{{lorem.words}}'),
preText: faker.fake('{{lorem.words}}'),
testing: true,
color: {
incomplete: 'yellow',
success: 'cyan',
error: 'magenta'
},
symbol: {
incomplete: null,
success: 'o',
error: 'x'
}
}
const m = new Multispinner(spinners, opts)
Object.keys(opts).map(prop => {
assert.deepEqual(opts[prop], m[prop])
})
})
it('Handle partially configured property object', () => {
const opts = {
testing: true,
color: {
incomplete: 'yellow'
}
}
// build expected color object
const expected = clone(defaultProps.color)
expected.incomplete = 'yellow'
// instantiate and test
const m = new Multispinner(spinners, opts)
assert.deepEqual(expected, m.color)
})
describe('compute and bind computed props', () => {
it('frames and frameCount', () => {
const frames = ['x', '+']
const m = new Multispinner(spinners, {
frames,
testing: true
})
assert.equal(2, m.frameCount)
assert.equal(frames, m.frames)
})
it('indentStr', () => {
const m = new Multispinner(spinners, {
testing: true,
indent: 4
})
assert.equal(' '.repeat(4), m.indentStr)
})
})
it('Props do not leak between instances', () => {
const m = new Multispinner(spinners, {testing: true})
const spinners2 = genSpinners.arr(3)
const m2 = new Multispinner(spinners2, {testing: true})
spinners.map(spinner => {
assert.isFalse(m2.spinners.hasOwnProperty(spinner))
})
})
it('Instantiate spinners', () => {
const m = new Multispinner(spinners, {testing: true})
const s = new Spinners(spinners, m.preText, m.postText).spinners()
assert.deepEqual(m.spinners, s)
})
it('LogUpdate to stream if testing is true', () => {
const m = new Multispinner(spinners, {testing: true})
assert.deepEqual(
logUpdate.create().toString(),
m.update.toString()
)
})
})