-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
83 lines (75 loc) · 1.76 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
/*!
* right-pad-values <https://github.com/jonschlinkert/right-pad-values>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var pad = require('./');
var arr = [{a: 'b'}, {a: 'bb'}, {a: 'bbbb'}, {a: 'bbb'}, {a: 'bb'}];
describe('right pad values', function() {
describe('array:', function() {
it('should right-pad the values for the given property:', function() {
assert.deepEqual(pad(arr, 'a'), [
{a: 'b '},
{a: 'bb '},
{a: 'bbbb'},
{a: 'bbb '},
{a: 'bb '}
]);
});
});
describe('object:', function() {
it('should right-pad the values of an object:', function() {
assert.deepEqual(pad({a: 'b', c: 'dddddd', e: 'fff', g: 'hhhhh'}), {
a: 'b ',
c: 'dddddd',
e: 'fff ',
g: 'hhhhh ',
});
});
});
describe('objects:', function() {
it('should right-pad values of a specific object property:', function() {
var res = pad('foo', {
a: {
foo: 'a',
bar: 'z'
},
b: {
foo: 'aaaaaaa',
bar: 'z'
},
c: {
foo: 'aaa',
bar: 'z'
}
});
assert.deepEqual(res, {
a: {
foo: 'a ',
bar: 'z'
},
b: {
foo: 'aaaaaaa',
bar: 'z'
},
c: {
foo: 'aaa ',
bar: 'z'
}
});
});
});
it('should throw an error when an array is not passed:', function(cb) {
try {
pad();
cb(new Error('expected an error'));
} catch (err) {
assert.equal(err.message, 'right-pad-values expects an object or array.');
cb();
}
});
});