Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for KuCalc : devops.
Download
50655 views
1
/*
2
* utile-test.js: Tests for `utile` module.
3
*
4
* (C) 2011, Nodejitsu Inc.
5
* MIT LICENSE
6
*
7
*/
8
9
var assert = require('assert'),
10
vows = require('vows'),
11
utile = require('../lib');
12
13
var obj1, obj2;
14
15
obj1 = {
16
foo: true,
17
bar: {
18
bar1: true,
19
bar2: 'bar2'
20
}
21
};
22
23
obj2 = {
24
baz: true,
25
buzz: 'buzz'
26
};
27
obj2.__defineGetter__('bazz', function () {
28
return 'bazz';
29
});
30
31
vows.describe('utile').addBatch({
32
"When using utile": {
33
"it should have the same methods as the `util` module": function () {
34
Object.keys(require('util')).forEach(function (fn) {
35
if (fn !== 'inspect') {
36
assert.isFunction(utile[fn]);
37
}
38
});
39
},
40
"it should have the correct methods defined": function () {
41
assert.isFunction(utile.mixin);
42
assert.isFunction(utile.clone);
43
assert.isFunction(utile.rimraf);
44
assert.isFunction(utile.mkdirp);
45
assert.isFunction(utile.cpr);
46
},
47
"the mixin() method": function () {
48
var mixed = utile.mixin({}, obj1, obj2);
49
assert.isTrue(mixed.foo);
50
assert.isObject(mixed.bar);
51
assert.isTrue(mixed.baz);
52
assert.isString(mixed.buzz);
53
assert.isTrue(!!mixed.__lookupGetter__('bazz'));
54
assert.isString(mixed.bazz);
55
},
56
"the clone() method": function () {
57
var clone = utile.clone(obj1);
58
assert.isTrue(clone.foo);
59
assert.isObject(clone.bar);
60
assert.notStrictEqual(obj1, clone);
61
},
62
"the createPath() method": function () {
63
var x = {},
64
r = Math.random();
65
66
utile.createPath(x, ['a','b','c'], r)
67
assert.equal(x.a.b.c, r)
68
}
69
}
70
}).export(module);
71
72
73