@@ -12,21 +12,60 @@ var {
12
12
Bar,
13
13
EchoFooProp,
14
14
Foo,
15
+ Async,
15
16
Nested,
16
17
EchoBarParam,
17
- RedirectToFoo
18
+ RedirectToFoo,
19
+ RedirectToFooAsync,
20
+ Abort,
21
+ AbortAsync
18
22
} = require ( './TestHandlers' ) ;
19
23
20
24
describe ( 'Router' , function ( ) {
21
25
describe ( 'transitions' , function ( ) {
22
26
23
27
var routes = [
24
28
< Route path = "/redirect" handler = { RedirectToFoo } /> ,
25
- < Route path = "/foo" handler = { Foo } />
29
+ < Route path = "/redirect-async" handler = { RedirectToFooAsync } /> ,
30
+ < Route path = "/abort" handler = { Abort } /> ,
31
+ < Route path = "/abort-async" handler = { AbortAsync } /> ,
32
+ < Route path = "/foo" handler = { Foo } /> ,
33
+ < Route path = "/bar" handler = { Bar } /> ,
34
+ < Route path = "/async" handler = { Async } />
26
35
] ;
27
36
37
+ describe ( 'transition.wait' , function ( ) {
38
+ it ( 'waits asynchronously in willTransitionTo' , function ( done ) {
39
+ TestLocation . history = [ '/bar' ] ;
40
+
41
+ var div = document . createElement ( 'div' ) ;
42
+ var steps = [ ] ;
43
+
44
+ steps . push ( function ( ) {
45
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
46
+ TestLocation . push ( '/async' ) ;
47
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
48
+
49
+ setTimeout ( function ( ) {
50
+ expect ( div . innerHTML ) . toMatch ( / A s y n c / ) ;
51
+ done ( ) ;
52
+ } , Async . delay + 10 ) ;
53
+ } ) ;
54
+
55
+ steps . push ( function ( ) {
56
+ expect ( div . innerHTML ) . toMatch ( / A s y n c / ) ;
57
+ } ) ;
58
+
59
+ Router . run ( routes , TestLocation , function ( Handler ) {
60
+ React . render ( < Handler /> , div , function ( ) {
61
+ steps . shift ( ) ( ) ;
62
+ } ) ;
63
+ } ) ;
64
+ } ) ;
65
+ } ) ;
66
+
28
67
describe ( 'transition.redirect' , function ( ) {
29
- it ( 'redirects in willTransitionTo' , function ( done ) {
68
+ it ( 'redirects synchronously in willTransitionTo' , function ( done ) {
30
69
TestLocation . history = [ '/redirect' ] ;
31
70
32
71
var div = document . createElement ( 'div' ) ;
@@ -38,10 +77,80 @@ describe('Router', function () {
38
77
} ) ;
39
78
} ) ;
40
79
} ) ;
80
+
81
+ it ( 'redirects asynchronously in willTransitionTo' , function ( done ) {
82
+ TestLocation . history = [ '/bar' ] ;
83
+
84
+ var div = document . createElement ( 'div' ) ;
85
+ var steps = [ ] ;
86
+
87
+ steps . push ( function ( ) {
88
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
89
+ TestLocation . push ( '/redirect-async' ) ;
90
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
91
+
92
+ setTimeout ( function ( ) {
93
+ expect ( div . innerHTML ) . toMatch ( / F o o / ) ;
94
+ done ( ) ;
95
+ } , RedirectToFooAsync . delay + 10 ) ;
96
+ } ) ;
97
+
98
+ steps . push ( function ( ) {
99
+ expect ( div . innerHTML ) . toMatch ( / F o o / ) ;
100
+ done ( ) ;
101
+ } ) ;
102
+
103
+ Router . run ( routes , TestLocation , function ( Handler ) {
104
+ React . render ( < Handler /> , div , function ( ) {
105
+ steps . shift ( ) ( ) ;
106
+ } ) ;
107
+ } ) ;
108
+ } ) ;
41
109
} ) ;
42
110
43
111
describe ( 'transition.abort' , function ( ) {
44
- it ( 'aborts in willTransitionTo' ) ;
112
+ it ( 'aborts synchronously in willTransitionTo' , function ( done ) {
113
+ TestLocation . history = [ '/foo' ] ;
114
+
115
+ var div = document . createElement ( 'div' ) ;
116
+
117
+ Router . run ( routes , TestLocation , function ( Handler ) {
118
+ React . render ( < Handler /> , div , function ( ) {
119
+ TestLocation . push ( '/abort' ) ;
120
+ expect ( div . innerHTML ) . toMatch ( / F o o / ) ;
121
+ expect ( TestLocation . getCurrentPath ( ) === 'foo' ) ;
122
+ done ( ) ;
123
+ } ) ;
124
+ } ) ;
125
+ } ) ;
126
+
127
+ it ( 'aborts asynchronously in willTransitionTo' , function ( done ) {
128
+ TestLocation . history = [ '/bar' ] ;
129
+
130
+ var div = document . createElement ( 'div' ) ;
131
+ var steps = [ ] ;
132
+
133
+ steps . push ( function ( ) {
134
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
135
+ TestLocation . push ( '/abort-async' ) ;
136
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
137
+
138
+ setTimeout ( function ( ) {
139
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
140
+ done ( ) ;
141
+ } , AbortAsync . delay + 10 ) ;
142
+ } ) ;
143
+
144
+ steps . push ( function ( ) {
145
+ expect ( div . innerHTML ) . toMatch ( / B a r / ) ;
146
+ } ) ;
147
+
148
+ Router . run ( routes , TestLocation , function ( Handler ) {
149
+ React . render ( < Handler /> , div , function ( ) {
150
+ steps . shift ( ) ( ) ;
151
+ } ) ;
152
+ } ) ;
153
+ } ) ;
45
154
} ) ;
46
155
} ) ;
47
156
0 commit comments