1
1
/* eslint max-nested-callbacks: 0 */
2
2
import { describe , it } from 'mocha'
3
3
import assert from 'assert'
4
- import { createMockHistory } from './helper/mockHistory'
5
- import { makeRouterDriver } from '../src'
4
+ import { makeRouterDriver , createServerHistory } from '../src'
6
5
7
6
describe ( 'Cyclic Router' , ( ) => {
8
7
describe ( 'makeRouterDriver' , ( ) => {
@@ -14,15 +13,15 @@ describe('Cyclic Router', () => {
14
13
15
14
it ( 'should accept any object with a listen() method' , ( ) => {
16
15
assert . doesNotThrow ( ( ) => {
17
- makeRouterDriver ( createMockHistory ( ) )
16
+ makeRouterDriver ( createServerHistory ( ) )
18
17
} )
19
18
} )
20
19
21
20
describe ( 'routerDriver' , ( ) => {
22
21
it ( 'should return an object with `path` `define` `observable` ' +
23
22
'`createHref` and `dispose`' ,
24
23
( ) => {
25
- const router = makeRouterDriver ( createMockHistory ( ) ) ( )
24
+ const router = makeRouterDriver ( createServerHistory ( ) ) ( )
26
25
assert . notStrictEqual ( router . path , null )
27
26
assert . strictEqual ( typeof router . path , 'function' )
28
27
assert . notStrictEqual ( router . define , null )
@@ -42,7 +41,7 @@ describe('Cyclic Router', () => {
42
41
it ( 'should return an object with `path` `define` `observable` ' +
43
42
'`createHref` and `dispose`' ,
44
43
( ) => {
45
- const router = makeRouterDriver ( createMockHistory ( ) ) ( ) . path ( '/' )
44
+ const router = makeRouterDriver ( createServerHistory ( ) ) ( ) . path ( '/' )
46
45
assert . notStrictEqual ( router . path , null )
47
46
assert . strictEqual ( typeof router . path , 'function' )
48
47
assert . notStrictEqual ( router . define , null )
@@ -61,7 +60,7 @@ describe('Cyclic Router', () => {
61
60
'/somewhere/else' ,
62
61
'/path/that/is/correct' ,
63
62
]
64
- const history = createMockHistory ( routes )
63
+ const history = createServerHistory ( routes )
65
64
const router = makeRouterDriver ( history ) ( ) . path ( '/path' )
66
65
67
66
router . observable . subscribe ( ( location ) => {
@@ -77,7 +76,7 @@ describe('Cyclic Router', () => {
77
76
'/some/really/really/deeply/nested/incorrect/route' ,
78
77
]
79
78
80
- const history = createMockHistory ( routes )
79
+ const history = createServerHistory ( routes )
81
80
const router = makeRouterDriver ( history ) ( )
82
81
. path ( '/some' ) . path ( '/really' ) . path ( '/really' ) . path ( '/deeply' )
83
82
. path ( '/nested' ) . path ( '/route' ) . path ( '/that' )
@@ -95,7 +94,7 @@ describe('Cyclic Router', () => {
95
94
'/some/really/really/deeply/nested/incorrect/route' ,
96
95
]
97
96
98
- const history = createMockHistory ( routes )
97
+ const history = createServerHistory ( routes )
99
98
const router = makeRouterDriver ( history ) ( )
100
99
. path ( '/some' ) . path ( '/really' ) . path ( '/really' ) . path ( '/deeply' )
101
100
. path ( '/nested' ) . path ( '/route' ) . path ( '/that' )
@@ -116,7 +115,7 @@ describe('Cyclic Router', () => {
116
115
'/some/really/really/deeply/nested/incorrect/route' ,
117
116
]
118
117
119
- const history = createMockHistory ( routes )
118
+ const history = createServerHistory ( routes )
120
119
const router = makeRouterDriver ( history ) ( )
121
120
. path ( '/some' ) . path ( '/really' ) . path ( '/really' ) . path ( '/deeply' )
122
121
. path ( '/nested' ) . path ( '/route' ) . path ( '/that' )
@@ -131,7 +130,7 @@ describe('Cyclic Router', () => {
131
130
it ( 'should return an object with `path$` `value$` `fullPath$` ' +
132
131
'`createHref` and `dispose`' ,
133
132
( ) => {
134
- const router = makeRouterDriver ( createMockHistory ( ) ) ( ) . define ( { } )
133
+ const router = makeRouterDriver ( createServerHistory ( ) ) ( ) . define ( { } )
135
134
assert . notStrictEqual ( router . path$ , null )
136
135
assert . strictEqual ( typeof router . path$ , 'object' )
137
136
assert . strictEqual ( typeof router . path$ . subscribe , 'function' )
@@ -157,7 +156,7 @@ describe('Cyclic Router', () => {
157
156
const routes = [
158
157
'/some/route' ,
159
158
]
160
- const history = createMockHistory ( routes )
159
+ const history = createServerHistory ( )
161
160
const { path$, value$, fullPath$} =
162
161
makeRouterDriver ( history ) ( ) . define ( defintion )
163
162
@@ -173,6 +172,8 @@ describe('Cyclic Router', () => {
173
172
assert . strictEqual ( fullPath , '/some/route' )
174
173
setTimeout ( done , 10 )
175
174
} )
175
+
176
+ routes . forEach ( r => history . push ( r ) )
176
177
} )
177
178
178
179
it ( 'should respect prior filtering by path()' , done => {
@@ -187,7 +188,7 @@ describe('Cyclic Router', () => {
187
188
'/some/nested/correct/route' ,
188
189
'/wrong/route' ,
189
190
]
190
- const history = createMockHistory ( routes )
191
+ const history = createServerHistory ( )
191
192
const { path$, value$, fullPath$} = makeRouterDriver ( history ) ( )
192
193
. path ( '/some' ) . path ( '/nested' ) . define ( defintion )
193
194
@@ -203,6 +204,8 @@ describe('Cyclic Router', () => {
203
204
assert . strictEqual ( fullPath , '/some/nested/correct/route' )
204
205
setTimeout ( done , 10 )
205
206
} )
207
+
208
+ routes . forEach ( r => history . push ( r ) )
206
209
} )
207
210
208
211
it ( 'should match a default route if one is not found' , done => {
@@ -218,7 +221,7 @@ describe('Cyclic Router', () => {
218
221
'/some/nested/incorrect/route' ,
219
222
'/wrong/route' ,
220
223
]
221
- const history = createMockHistory ( routes )
224
+ const history = createServerHistory ( )
222
225
const { path$, value$, fullPath$} = makeRouterDriver ( history ) ( )
223
226
. path ( '/some' ) . path ( '/nested' ) . define ( defintion )
224
227
@@ -234,6 +237,8 @@ describe('Cyclic Router', () => {
234
237
assert . strictEqual ( fullPath , '/some/nested/incorrect/route' )
235
238
setTimeout ( done , 10 )
236
239
} )
240
+
241
+ routes . forEach ( r => history . push ( r ) )
237
242
} )
238
243
239
244
it ( 'should create a proper href using createHref()' , done => {
@@ -250,7 +255,7 @@ describe('Cyclic Router', () => {
250
255
'/wrong/route' ,
251
256
]
252
257
253
- const history = createMockHistory ( routes )
258
+ const history = createServerHistory ( )
254
259
const { fullPath$, createHref} = makeRouterDriver ( history ) ( )
255
260
. path ( '/some' ) . path ( '/nested' ) . define ( defintion )
256
261
@@ -259,6 +264,8 @@ describe('Cyclic Router', () => {
259
264
assert . strictEqual ( createHref ( '/correct/route' ) , pathname )
260
265
setTimeout ( done , 5 )
261
266
} )
267
+
268
+ routes . forEach ( r => history . push ( r ) )
262
269
} )
263
270
264
271
it ( 'should match partials' , done => {
@@ -275,7 +282,7 @@ describe('Cyclic Router', () => {
275
282
'/wrong/route' ,
276
283
]
277
284
278
- const history = createMockHistory ( routes )
285
+ const history = createServerHistory ( )
279
286
const { path$, fullPath$} = makeRouterDriver ( history ) ( )
280
287
. path ( '/some' ) . path ( '/nested' ) . define ( defintion )
281
288
@@ -287,6 +294,8 @@ describe('Cyclic Router', () => {
287
294
assert . strictEqual ( pathname , '/some/nested/correct/route/partial' )
288
295
setTimeout ( done , 5 )
289
296
} )
297
+
298
+ routes . forEach ( r => history . push ( r ) )
290
299
} )
291
300
292
301
it ( 'should not work after being disposed' , done => {
@@ -303,12 +312,13 @@ describe('Cyclic Router', () => {
303
312
'/wrong/route' ,
304
313
]
305
314
306
- const history = createMockHistory ( routes )
315
+ const history = createServerHistory ( )
307
316
const { fullPath$, dispose} = makeRouterDriver ( history ) ( )
308
317
. path ( '/some' ) . path ( '/nested' ) . define ( defintion )
309
318
310
319
dispose ( )
311
320
fullPath$ . subscribe ( done . fail )
321
+ routes . forEach ( r => history . push ( r ) )
312
322
setTimeout ( done , 10 )
313
323
} )
314
324
} )
0 commit comments