@@ -4,12 +4,7 @@ import * as React from 'react';
4
4
import * as PropTypes from 'prop-types' ;
5
5
import { mount } from 'enzyme' ;
6
6
7
- import {
8
- UIRouter ,
9
- UIRouterConsumer ,
10
- UIRouterReact ,
11
- memoryLocationPlugin ,
12
- } from '../../index' ;
7
+ import { UIRouter , UIRouterConsumer , UIRouterReact , memoryLocationPlugin } from '../../index' ;
13
8
14
9
class Child extends React . Component < any , any > {
15
10
static propTypes : React . ValidationMap < any > = {
@@ -34,9 +29,7 @@ describe('<UIRouter>', () => {
34
29
it ( 'creates a router instance' , ( ) => {
35
30
const wrapper = mount (
36
31
< UIRouter plugins = { [ memoryLocationPlugin ] } states = { [ ] } >
37
- < UIRouterConsumer >
38
- { router => < Child router = { router } /> }
39
- </ UIRouterConsumer >
32
+ < UIRouterConsumer > { router => < Child router = { router } /> } </ UIRouterConsumer >
40
33
</ UIRouter > ,
41
34
) ;
42
35
expect ( wrapper . find ( Child ) . props ( ) . router ) . toBeDefined ( ) ;
@@ -45,14 +38,41 @@ describe('<UIRouter>', () => {
45
38
it ( 'accepts an instance via prop' , ( ) => {
46
39
const router = new UIRouterReact ( ) ;
47
40
router . plugin ( memoryLocationPlugin ) ;
48
- ( router as any ) . __TEST__ = true ;
49
41
const wrapper = mount (
50
42
< UIRouter router = { router } >
51
- < UIRouterConsumer >
52
- { router => < Child router = { router } /> }
53
- </ UIRouterConsumer >
43
+ < UIRouterConsumer > { router => < Child router = { router } /> } </ UIRouterConsumer >
54
44
</ UIRouter > ,
55
45
) ;
56
- expect ( wrapper . find ( Child ) . props ( ) . router . __TEST__ ) . toBe ( true ) ;
46
+ expect ( wrapper . find ( Child ) . props ( ) . router ) . toBe ( router ) ;
47
+ } ) ;
48
+
49
+ describe ( '<UIRouterCosumer>' , ( ) => {
50
+ it ( 'passes down the router instance' , ( ) => {
51
+ const wrapper = mount (
52
+ < UIRouter plugins = { [ memoryLocationPlugin ] } >
53
+ < UIRouterConsumer >
54
+ { router => {
55
+ expect ( router ) . toBeInstanceOf ( UIRouterReact ) ;
56
+ return null ;
57
+ } }
58
+ </ UIRouterConsumer >
59
+ </ UIRouter > ,
60
+ ) ;
61
+ } ) ;
62
+
63
+ it ( 'passes down the correct router instance when passed via props' , ( ) => {
64
+ const router = new UIRouterReact ( ) ;
65
+ router . plugin ( memoryLocationPlugin ) ;
66
+ const wrapper = mount (
67
+ < UIRouter router = { router } >
68
+ < UIRouterConsumer >
69
+ { _router => {
70
+ expect ( _router ) . toBe ( router ) ;
71
+ return null ;
72
+ } }
73
+ </ UIRouterConsumer >
74
+ </ UIRouter > ,
75
+ ) ;
76
+ } ) ;
57
77
} ) ;
58
78
} ) ;
0 commit comments