Skip to content

Commit cd8f1ba

Browse files
committed
Add isActive test with a custom parse/stringify function
1 parent 8ef625e commit cd8f1ba

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

modules/__tests__/isActive-test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import createHistory from 'history/lib/createMemoryHistory'
55
import IndexRoute from '../IndexRoute'
66
import Router from '../Router'
77
import Route from '../Route'
8+
import qs from 'qs'
89

910
describe('isActive', function () {
1011

@@ -106,6 +107,27 @@ describe('isActive', function () {
106107
})
107108
})
108109
})
110+
111+
describe('with a custom parse function and a query that does not match', function () {
112+
it('is not active', function (done) {
113+
function stringifyQuery(params) {
114+
return qs.stringify(params, { arrayFormat: 'indices' })
115+
}
116+
function parseQueryString(query) {
117+
return qs.parse(query, { arrayLimit: 0 })
118+
}
119+
120+
React.render((
121+
<Router history={createHistory('/home?foo[4]=bar')} stringifyQuery={stringifyQuery} parseQueryString={parseQueryString}>
122+
<Route path="/" />
123+
<Route path="/home" />
124+
</Router>
125+
), node, function () {
126+
expect(this.history.isActive('/home', { foo: { 1: 'bar' } })).toBe(false)
127+
done()
128+
})
129+
})
130+
})
109131
})
110132

111133
describe('a pathname that matches an index URL', function () {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"karma-sourcemap-loader": "^0.3.5",
5252
"karma-webpack": "^1.7.0",
5353
"mocha": "^2.0.1",
54+
"qs": "^4.0.0",
5455
"react": "0.13.x",
5556
"rf-changelog": "^0.4.0",
5657
"style-loader": "^0.12.4",

0 commit comments

Comments
 (0)