-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (59 loc) · 1.68 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
const autobind = require(".").autobind;
const autobindReact = require(".").react;
console.log("start");
console.log(autobindReact);
function constructSpell(element) {
return `${element} enfold everywhere!`;
}
class Witch {
constructor(element) {
this._other = {};
this._element = element;
autobind(this);
}
spell() {
return constructSpell(this._element);
}
}
class WitchExclude {
constructor(element) {
this._other = {};
this._element = element;
autobindReact(this);
}
spell() {
return constructSpell(this._element);
}
componentDidMount() {
if (this === undefined) {
throw new Error();
}
return constructSpell(this._element);
}
}
test("returns bound instance", () => {
const witch = new Witch("Ice");
const bounded = autobind(witch);
expect(bounded).toBe(witch);
});
test("binds methods", () => {
const element = "Ice";
const referenceSpell = constructSpell(element);
const iceWitch = new Witch(element);
const { spell : iceWitchSpell } = iceWitch;
expect(referenceSpell).toBe(iceWitchSpell());
});
test("excludes excluded methods", () => {
const element = "Ice";
const referenceSpell = constructSpell(element);
const iceWitch = new WitchExclude(element);
const { componentDidMount : iceWitchExcludedSpell } = iceWitch;
expect(iceWitchExcludedSpell).toThrow();
});
test("excludes excluded methods", () => {
const element = "Ice";
const referenceSpell = constructSpell(element);
const iceWitch = new WitchExclude(element);
const { componentDidMount : iceWitchExcludedSpell } = iceWitch;
expect(iceWitchExcludedSpell).toThrow();
});