@@ -5,6 +5,7 @@ import createHistory from 'history/lib/createMemoryHistory'
5
5
import IndexRoute from '../IndexRoute'
6
6
import Router from '../Router'
7
7
import Route from '../Route'
8
+ import qs from 'qs'
8
9
9
10
describe ( 'isActive' , function ( ) {
10
11
@@ -200,4 +201,61 @@ describe('isActive', function () {
200
201
} )
201
202
} )
202
203
204
+ describe ( 'a pathname that matches URL' , function ( ) {
205
+ describe ( 'with query that does match' , function ( ) {
206
+ it ( 'is active' , function ( done ) {
207
+ React . render ( (
208
+ < Router history = { createHistory ( '/home?foo[]=bar&foo[]=bar1&foo[]=bar2' ) } >
209
+ < Route path = "/" />
210
+ < Route path = "/home" />
211
+ </ Router >
212
+ ) , node , function ( ) {
213
+ expect ( this . history . isActive ( '/home' , { foo : [ 'bar' , 'bar1' , 'bar2' ] } ) ) . toBe ( true )
214
+ done ( )
215
+ } )
216
+ } )
217
+ } )
218
+
219
+ describe ( 'with a custom parse function and a query that does not match' , function ( ) {
220
+ it ( 'is not active' , function ( done ) {
221
+ function stringifyQuery ( params ) {
222
+ return qs . stringify ( params , { arrayFormat : 'indices' } )
223
+ }
224
+ function parseQueryString ( query ) {
225
+ return qs . parse ( query , { parseArrays : false } )
226
+ }
227
+
228
+ React . render ( (
229
+ < Router history = { createHistory ( '/home?foo[1]=bar' ) } stringifyQuery = { stringifyQuery } parseQueryString = { parseQueryString } >
230
+ < Route path = "/" />
231
+ < Route path = "/home" />
232
+ </ Router >
233
+ ) , node , function ( ) {
234
+ expect ( this . history . isActive ( '/home' , { foo : { 4 : 'bar' } } ) ) . toBe ( false )
235
+ done ( )
236
+ } )
237
+ } )
238
+ } )
239
+
240
+ describe ( 'with a custom parse function and a query that match' , function ( ) {
241
+ it ( 'is active' , function ( done ) {
242
+ function stringifyQuery ( params ) {
243
+ return qs . stringify ( params , { arrayFormat : 'indices' } )
244
+ }
245
+ function parseQueryString ( query ) {
246
+ return qs . parse ( query , { parseArrays : false } )
247
+ }
248
+
249
+ React . render ( (
250
+ < Router history = { createHistory ( '/home?foo[4]=bar&foo[1]=bar2' ) } stringifyQuery = { stringifyQuery } parseQueryString = { parseQueryString } >
251
+ < Route path = "/" />
252
+ < Route path = "/home" />
253
+ </ Router >
254
+ ) , node , function ( ) {
255
+ expect ( this . history . isActive ( '/home' , { foo : { 1 : 'bar2' , 4 : 'bar' } } ) ) . toBe ( true )
256
+ done ( )
257
+ } )
258
+ } )
259
+ } )
260
+ } )
203
261
} )
0 commit comments