11import expect from 'expect' ;
22import React from 'react' ;
33import createHistory from 'history/lib/createMemoryHistory' ;
4+ import IndexRoute from '../IndexRoute' ;
45import Router from '../Router' ;
56import Route from '../Route' ;
67
@@ -67,6 +68,7 @@ describe('isActive', function () {
6768 </ Router >
6869 ) , node , function ( ) {
6970 expect ( this . history . isActive ( '/home' ) ) . toBe ( true ) ;
71+ expect ( this . history . isActive ( '/home' , null , true ) ) . toBe ( false ) ;
7072 done ( ) ;
7173 } ) ;
7274 } ) ;
@@ -82,6 +84,7 @@ describe('isActive', function () {
8284 </ Router >
8385 ) , node , function ( ) {
8486 expect ( this . history . isActive ( '/home' , { the : 'query' } ) ) . toBe ( true ) ;
87+ expect ( this . history . isActive ( '/home' , { the : 'query' } , true ) ) . toBe ( false ) ;
8588 done ( ) ;
8689 } ) ;
8790 } ) ;
@@ -97,6 +100,57 @@ describe('isActive', function () {
97100 </ Router >
98101 ) , node , function ( ) {
99102 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 ) ;
100154 done ( ) ;
101155 } ) ;
102156 } ) ;
0 commit comments