-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
46 lines (42 loc) · 1.35 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
'use strict';
var assert = require('assert');
var delegate = require('./');
describe('delegate-object', function () {
it('should delegate all properties', function () {
var receiver = {};
var provider = {
name: 'provider',
upper: function (str) {
return '[' + this.name + '] ' + str.toUpperCase();
}
};
var receiver = delegate(receiver, provider);
assert.deepEqual(Object.keys(receiver), Object.keys(provider));
});
it('should delegate specified properties', function () {
var receiver = {};
var provider = {
name: 'provider',
foo: 'bar',
upper: function (str) {
return '[' + this.name + '] ' + str.toUpperCase();
}
};
var receiver = delegate(receiver, provider, ['name', 'upper']);
assert.deepEqual(Object.keys(receiver), ['name', 'upper']);
});
it('should execute methods with the context of the receiver', function () {
var receiver = {};
var provider = {
name: 'provider',
upper: function (str) {
return '[' + this.name + '] ' + str.toUpperCase();
}
};
var receiver = delegate(receiver, provider, ['name', 'upper']);
receiver.name = 'receiver',
assert.deepEqual(receiver.name, 'receiver');
assert.deepEqual(provider.name, 'provider');
assert.deepEqual(receiver.upper('foo'), '[receiver] FOO');
});
});