-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathutils.js
67 lines (61 loc) · 1.48 KB
/
utils.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
'use strict';
describe('utils', function() {
var mod;
var sinon;
var prequire;
var path;
var assert;
var importsStub;
before(function() {
sinon = require('sinon');
prequire = require('proxyquire');
path = require('path');
assert = require('assert');
importsStub = {
helpers: {
Map: {}
}
};
mod = prequire(
path.resolve('src', 'utils.js'),
{'./imports': importsStub}
);
});
describe('#addFinalProp', function() {
it('should set the prop to the given value', function() {
var obj = {};
mod.addFinalProp(obj, 'a', 'asdf');
assert.equal(obj.a, 'asdf');
});
it('should not set the prop when the given value is undefined', function() {
var obj = {};
mod.addFinalProp(obj, 'a', ({}).asdf);
assert.equal(obj.a, void 0);
});
});
describe('#extendAll', function() {
it('is callable', function() {
function A() {
}
function B() {
}
function C() {
}
B.bar = 'bar';
A.prototype.name = 'A';
B.prototype.name = 'B';
C.prototype.name = 'C';
B.prototype.bar = 'bar';
B.prototype.foo = 'boo';
C.prototype.foo = 'foo';
mod.extendAll(A, B, C);
var instance = new A();
assert.equal(instance.name, 'A');
assert.equal(instance.bar, 'bar');
assert.equal(instance.foo, 'boo');
assert.equal(A.bar, 'bar');
assert(A.__extends.B);
assert(A.__extends.C);
});
});
});