@@ -6,6 +6,7 @@ import { routerShape } from '../PropTypes'
6
6
import execSteps from './execSteps'
7
7
import Router from '../Router'
8
8
import Route from '../Route'
9
+ import match from '../match'
9
10
10
11
describe ( 'When a router enters a branch' , function ( ) {
11
12
let
@@ -397,13 +398,17 @@ describe('Changing location', () => {
397
398
cb ( )
398
399
} )
399
400
}
401
+ const onEnterError = ( state , replace , cb ) => {
402
+ cb ( new Error ( 'transition error' ) )
403
+ }
400
404
const createRoutes = ( { enter, change } ) => [
401
405
< Route path = "/" onChange = { change ? onChange : noop } component = { Text ( 'Home' ) } >
402
406
< Route path = "child1" component = { Text ( 'Child1' ) } />
403
407
< Route path = "child2" component = { Text ( 'Child2' ) } />
404
408
</ Route > ,
405
409
< Route path = "/foo" onEnter = { enter ? onEnter : noop } component = { Text ( 'Foo' ) } /> ,
406
- < Route path = "/bar" component = { Text ( 'Bar' ) } />
410
+ < Route path = "/bar" component = { Text ( 'Bar' ) } /> ,
411
+ < Route path = "/error" onEnter = { enter ? onEnterError : noop } component = { Text ( 'Error' ) } />
407
412
]
408
413
409
414
beforeEach ( ( ) => {
@@ -443,4 +448,16 @@ describe('Changing location', () => {
443
448
} )
444
449
} )
445
450
} )
451
+
452
+ it ( 'should pass error correctly' , ( done ) => {
453
+ const routes = createRoutes ( { enter : true } )
454
+
455
+ match ( { routes, location : '/error' } , ( error , redirectLocation , renderProps ) => {
456
+ expect ( error ) . toExist ( )
457
+ expect ( error . message ) . toEqual ( 'transition error' )
458
+ expect ( redirectLocation ) . toNotExist ( )
459
+ expect ( renderProps ) . toNotExist ( )
460
+ done ( )
461
+ } )
462
+ } )
446
463
} )
0 commit comments