-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
78 lines (70 loc) · 1.91 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
const assert = require('assert');
const { createContainer, strategies } = require('./index');
class MixinA {
regularMethod(input) {
return [this.constructor, input];
}
overrideMethod(input) {
return [this.constructor, input];
}
parallelMethod(input) {
return [this.constructor, input];
}
pipeMethod(input) {
return [this.constructor, input];
}
composeMethod(input) {
return [this.constructor, input];
}
}
MixinA.strategies = {
overrideMethod: strategies.override,
parallelMethod: strategies.parallel,
pipeMethod: strategies.pipe,
composeMethod: strategies.compose,
};
class MixinB {
regularMethod(input) {
return [this.constructor, input];
}
overrideMethod(input) {
return [this.constructor, input];
}
parallelMethod(input) {
return [this.constructor, input];
}
pipeMethod(input) {
return [this.constructor, input];
}
composeMethod(input) {
return [this.constructor, input];
}
}
const container = createContainer(MixinA, MixinB)();
// regularMethod is not available on container
{
assert.equal(typeof container.regularMethod, 'undefined');
}
// executes overrideMethod of MixinB only
{
const actual = container.overrideMethod('overrideMethod');
assert.deepEqual(actual, [MixinB, 'overrideMethod']);
}
// executes parallelMethod of MixinA and MixinB and returns results as array
{
const actual = container.parallelMethod('parallelMethod');
assert.deepEqual(actual, [
[MixinA, 'parallelMethod'],
[MixinB, 'parallelMethod'],
]);
}
// executes pipeMethod of MixinA and passes the result to pipeMethod of MixinB
{
const actual = container.pipeMethod('pipeMethod');
assert.deepEqual(actual, [MixinB, [MixinA, 'pipeMethod']]);
}
// executes composeMethod of MixinB and passes the result to composeMethod of MixinA
{
const actual = container.composeMethod('composeMethod');
assert.deepEqual(actual, [MixinA, [MixinB, 'composeMethod']]);
}