1
1
import expect from 'expect' ;
2
2
import React from 'react' ;
3
3
import createHistory from 'history/lib/createMemoryHistory' ;
4
+ import IndexRoute from '../IndexRoute' ;
4
5
import Router from '../Router' ;
5
6
import Route from '../Route' ;
6
7
@@ -67,6 +68,7 @@ describe('isActive', function () {
67
68
</ Router >
68
69
) , node , function ( ) {
69
70
expect ( this . history . isActive ( '/home' ) ) . toBe ( true ) ;
71
+ expect ( this . history . isActive ( '/home' , null , true ) ) . toBe ( false ) ;
70
72
done ( ) ;
71
73
} ) ;
72
74
} ) ;
@@ -82,6 +84,7 @@ describe('isActive', function () {
82
84
</ Router >
83
85
) , node , function ( ) {
84
86
expect ( this . history . isActive ( '/home' , { the : 'query' } ) ) . toBe ( true ) ;
87
+ expect ( this . history . isActive ( '/home' , { the : 'query' } , true ) ) . toBe ( false ) ;
85
88
done ( ) ;
86
89
} ) ;
87
90
} ) ;
@@ -97,6 +100,57 @@ describe('isActive', function () {
97
100
</ Router >
98
101
) , node , function ( ) {
99
102
expect ( this . history . isActive ( '/home' , { something : 'else' } ) ) . toBe ( false ) ;
103
+ expect ( this . history . isActive ( '/home' , { something : 'else' } , true ) ) . toBe ( false ) ;
104
+ done ( ) ;
105
+ } ) ;
106
+ } ) ;
107
+ } ) ;
108
+ } ) ;
109
+
110
+ describe ( 'a pathname that matches an index URL' , function ( ) {
111
+ describe ( 'with no query' , function ( ) {
112
+ it ( 'is active' , function ( done ) {
113
+ React . render ( (
114
+ < Router history = { createHistory ( '/home' ) } >
115
+ < Route path = "/home" >
116
+ < IndexRoute />
117
+ </ Route >
118
+ </ Router >
119
+ ) , node , function ( ) {
120
+ expect ( this . history . isActive ( '/home' , null ) ) . toBe ( true ) ;
121
+ expect ( this . history . isActive ( '/home' , null , true ) ) . toBe ( true ) ;
122
+ done ( ) ;
123
+ } ) ;
124
+ } ) ;
125
+ } ) ;
126
+
127
+ describe ( 'with a query that also matches' , function ( ) {
128
+ it ( 'is active' , function ( done ) {
129
+ React . render ( (
130
+ < Router history = { createHistory ( '/home?the=query' ) } >
131
+ < Route path = "/home" >
132
+ < IndexRoute />
133
+ </ Route >
134
+ </ Router >
135
+ ) , node , function ( ) {
136
+ expect ( this . history . isActive ( '/home' , { the : 'query' } ) ) . toBe ( true ) ;
137
+ expect ( this . history . isActive ( '/home' , { the : 'query' } , true ) ) . toBe ( true ) ;
138
+ done ( ) ;
139
+ } ) ;
140
+ } ) ;
141
+ } ) ;
142
+
143
+ describe ( 'with a query that does not match' , function ( ) {
144
+ it ( 'is not active' , function ( done ) {
145
+ React . render ( (
146
+ < Router history = { createHistory ( '/home?the=query' ) } >
147
+ < Route path = "/home" >
148
+ < IndexRoute />
149
+ </ Route >
150
+ </ Router >
151
+ ) , node , function ( ) {
152
+ expect ( this . history . isActive ( '/home' , { something : 'else' } ) ) . toBe ( false ) ;
153
+ expect ( this . history . isActive ( '/home' , { something : 'else' } , true ) ) . toBe ( false ) ;
100
154
done ( ) ;
101
155
} ) ;
102
156
} ) ;
0 commit comments