Skip to content

Commit 4bb335c

Browse files
committed
Tests and fixes for QuerystringKeyEnvironment.
1 parent 79573d2 commit 4bb335c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

lib/environment/QuerystringKeyEnvironment.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ QuerystringKeyEnvironment.prototype = Object.create(PathnameEnvironment.prototyp
1515
QuerystringKeyEnvironment.prototype.constructor = QuerystringKeyEnvironment;
1616

1717
QuerystringKeyEnvironment.prototype.getPath = function() {
18-
var path = PathnameEnvironment.prototype.getPath.call(this);
19-
if (path.indexOf('?') === -1) {
20-
return '/';
21-
}
22-
var query = qs.parse(path.split('?')[1] || '');
18+
var query = qs.parse(window.location.search.slice(1));
2319
return query[this.key] ? '/' + query[this.key] : '/';
2420
};
2521

tests/QueryStringKeyEnvironment.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
var assert = require('assert');
4+
var QuerystringKeyEnvironment = require('../lib/environment/QuerystringKeyEnvironment');
5+
6+
describe('QuerystringKeyEnvironment', function() {
7+
8+
var env;
9+
10+
beforeEach(function() {
11+
env = new QuerystringKeyEnvironment('key');
12+
});
13+
14+
afterEach(function() {
15+
window.history.pushState({}, '', '/');
16+
});
17+
18+
it('updates the corresponding key in querystring on setPath', function() {
19+
env.setPath('/x', {});
20+
assert.equal(location.search, '?key=x');
21+
});
22+
23+
it('returns a corresponding key from querystring via getPath', function() {
24+
assert.equal(env.getPath(), '/');
25+
window.history.pushState({}, '', '/?key=y');
26+
assert.equal(env.getPath(), '/y');
27+
});
28+
29+
});

0 commit comments

Comments
 (0)