Skip to content

Commit 0135eea

Browse files
committed
Add isActive tests
1 parent 7796b06 commit 0135eea

File tree

1 file changed

+57
-21
lines changed

1 file changed

+57
-21
lines changed

modules/__tests__/isActive-test.js

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,6 @@ describe('isActive', function () {
107107
})
108108
})
109109
})
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-
})
131110
})
132111

133112
describe('a pathname that matches an index URL', function () {
@@ -222,4 +201,61 @@ describe('isActive', function () {
222201
})
223202
})
224203

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+
})
225261
})

0 commit comments

Comments
 (0)