/
utils-test.js
72 lines (61 loc) · 1.64 KB
/
utils-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
var vows = require('vows');
var assert = require('assert');
var Utils = require('../lib/utils');
vows
.describe('Utils')
.addBatch({
'sync attributes': {
topic: Utils,
'knows about fields from first and second': function(utils) {
var first = {
foo: "Foo"
};
var second = {
zoom: "Zoom"
};
var third = utils.syncAttributes(first, second);
assert.equal(third.zoom, "Zoom");
assert.equal(third.foo, "Foo");
},
'returns an object of the first type': function(utils) {
var first = function() {
};
var second = function() {
};
var third = utils.syncAttributes(new first(), new second());
assert(third instanceof first);
},
'does not alter the second': function(utils) {
var first = {
zoom: "Zoom"
};
var second = {
zoom: "Not Zoom"
};
var third = utils.syncAttributes(first, second);
assert.equal(second.zoom, "Not Zoom");
},
'keeps the second objects fields in case of duplicates': function(utils) {
var first = {
zoom: "Zoom"
};
var second = {
zoom: "Not Zoom"
};
var third = utils.syncAttributes(first, second);
assert.equal(third.zoom, "Not Zoom");
},
'copies methods': function(utils) {
var first = {
foo: "Foo"
};
var second = {
doSomething: function() {
return "booom";
}
};
var third = utils.syncAttributes(first, second);
assert.equal(third.doSomething(), second.doSomething());
}
}
}).export(module);