/
alias_method_test.js
101 lines (85 loc) · 3.06 KB
/
alias_method_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { get, Mixin, mixin, aliasMethod } from '../..';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
function validateAliasMethod(assert, obj) {
assert.equal(obj.fooMethod(), 'FOO', 'obj.fooMethod()');
assert.equal(obj.barMethod(), 'FOO', 'obj.barMethod should be a copy of foo');
}
moduleFor(
'aliasMethod',
class extends AbstractTestCase {
['@test methods of another name are aliased when the mixin is applied'](assert) {
expectDeprecation(() => {
let MyMixin = Mixin.create({
fooMethod() {
return 'FOO';
},
barMethod: aliasMethod('fooMethod'),
});
let obj = MyMixin.apply({});
validateAliasMethod(assert, obj);
}, /aliasMethod has been deprecated. Consider extracting the method into a shared utility function/);
}
['@test should follow aliasMethods all the way down'](assert) {
expectDeprecation(() => {
let MyMixin = Mixin.create({
bar: aliasMethod('foo'), // put first to break ordered iteration
baz() {
return 'baz';
},
foo: aliasMethod('baz'),
});
let obj = MyMixin.apply({});
assert.equal(get(obj, 'bar')(), 'baz', 'should have followed aliasMethods');
}, /aliasMethod has been deprecated. Consider extracting the method into a shared utility function/);
}
['@test should alias methods from other dependent mixins'](assert) {
expectDeprecation(() => {
let BaseMixin = Mixin.create({
fooMethod() {
return 'FOO';
},
});
let MyMixin = Mixin.create(BaseMixin, {
barMethod: aliasMethod('fooMethod'),
});
let obj = MyMixin.apply({});
validateAliasMethod(assert, obj);
}, /aliasMethod has been deprecated. Consider extracting the method into a shared utility function/);
}
['@test should alias methods from other mixins applied at same time'](assert) {
expectDeprecation(() => {
let BaseMixin = Mixin.create({
fooMethod() {
return 'FOO';
},
});
let MyMixin = Mixin.create({
barMethod: aliasMethod('fooMethod'),
});
let obj = mixin({}, BaseMixin, MyMixin);
validateAliasMethod(assert, obj);
}, /aliasMethod has been deprecated. Consider extracting the method into a shared utility function/);
}
['@test should alias methods from mixins already applied on object'](assert) {
expectDeprecation(() => {
let BaseMixin = Mixin.create({
quxMethod() {
return 'qux';
},
});
let MyMixin = Mixin.create({
bar: aliasMethod('foo'),
barMethod: aliasMethod('fooMethod'),
});
let obj = {
fooMethod() {
return 'FOO';
},
};
BaseMixin.apply(obj);
MyMixin.apply(obj);
validateAliasMethod(assert, obj);
}, /aliasMethod has been deprecated. Consider extracting the method into a shared utility function/);
}
}
);