-
Notifications
You must be signed in to change notification settings - Fork 1
/
react-es6-autobind-tests.js
50 lines (44 loc) · 1.04 KB
/
react-es6-autobind-tests.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
Tinytest.add (
'methodCount',
function (test)
{
MyReactTestComponent = class MyReactTestComponent extends React.Component
{
constructor (props)
{
super (props);
}
customMethod ()
{
}
};
var instance = new MyReactTestComponent({});
var methodCount = SteinitzREA.getMethodsForInstance (instance).length;
var expectedMethodCount = 3; // customMethod, setState, forceUpdate
test.equal (methodCount, expectedMethodCount);
}
);
Tinytest.add (
'bindTest',
function (test)
{
MyReactTestComponent = class MyReactTestComponent extends React.Component
{
constructor (props)
{
super (props);
this.bindTest = this.bindTest.bind ({}); // simulate React environment
SteinitzREA.AutoBind (this); // fix the above binding
this.aValue = 'bind test';
}
bindTest (e)
{
return this.aValue;
}
};
var instance = new MyReactTestComponent({});
var bindTestValue = instance.bindTest();
var expectedMethodValue = 'bind test';
test.equal (bindTestValue, expectedMethodValue);
}
);