forked from RubyLouvre/anu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex9.html
102 lines (89 loc) · 2.39 KB
/
index9.html
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
102
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script type='text/javascript' src="./dist/React.js"></script>
<script type='text/javascript' src="./lib/ReactTestUtils.js"></script>
<!--<script src="./test/react.js"></script>
<script src="./test/react-dom.js"></script>-->
<script src="./lib/babel.js"></script>
</head>
<body>
<div>这个默认会被清掉</div>
<div id='example'></div>
<pre>
</pre>
<script type='text/babel'>
var container = document.getElementById("example")
var div = container
var expect = function(a) {
return {
toBe: function(b) {
console.log(a,"vs", b, a === b)
},
toEqual(b){
console.log(a,"vs", b, a +""=== b+"")
},
toThrow(b){
try{
a()
}catch(e){
console.log(e,"vs", b, e.message +""=== b+"")
}
}
}
}
var list = [];
class App extends React.Component {
constructor(props) {
super(props);
this.__merge = true
this.state = {
path: "111"
};
}
render() {
list.push("render " + this.state.path);
return (
<div>
<span ref="click2time" onClick={this.onClick.bind(this)}>
{this.state.path}
</span>
</div>
);
}
onClick() {
this.setState(
{
path: "click"
},
function() {
list.push("click....");
}
);
this.setState(
{
path: "click2"
},
function() {
list.push("click2....");
}
);
}
componentWillUpdate() {
list.push("will update");
}
componentDidUpdate() {
list.push("did update");
}
}
var s = ReactDOM.render(<App />, div, function() {
list.push("ReactDOM cb");
});
var list2 = ["render 111", "ReactDOM cb", "will update", "render click2", "did update", "click....", "click2...."];
ReactTestUtils.Simulate.click(s.refs.click2time);
expect(list).toEqual(list2);
</script>
</body>
</html>