The old style of merging all of a function's variable declarations into a single statement made some sense back in the days of var, but there's no reason to keep doing it now that we use const and let.
81 lines
2.2 KiB
JavaScript
81 lines
2.2 KiB
JavaScript
describe('QueryString', function() {
|
|
describe('#navigateWithNewParam', function() {
|
|
it('sets the query string to include the given key/value pair', function() {
|
|
const windowLocation = {
|
|
search: ''
|
|
};
|
|
const queryString = new jasmineUnderTest.QueryString({
|
|
getWindowLocation: function() {
|
|
return windowLocation;
|
|
}
|
|
});
|
|
|
|
queryString.navigateWithNewParam('foo', 'bar baz');
|
|
|
|
expect(windowLocation.search).toMatch(/foo=bar%20baz/);
|
|
});
|
|
|
|
it('leaves existing params alone', function() {
|
|
const windowLocation = {
|
|
search: '?foo=bar'
|
|
};
|
|
const queryString = new jasmineUnderTest.QueryString({
|
|
getWindowLocation: function() {
|
|
return windowLocation;
|
|
}
|
|
});
|
|
|
|
queryString.navigateWithNewParam('baz', 'quux');
|
|
|
|
expect(windowLocation.search).toMatch(/foo=bar/);
|
|
expect(windowLocation.search).toMatch(/baz=quux/);
|
|
});
|
|
});
|
|
|
|
describe('#fullStringWithNewParam', function() {
|
|
it('gets the query string including the given key/value pair', function() {
|
|
const windowLocation = {
|
|
search: '?foo=bar'
|
|
};
|
|
const queryString = new jasmineUnderTest.QueryString({
|
|
getWindowLocation: function() {
|
|
return windowLocation;
|
|
}
|
|
});
|
|
|
|
const result = queryString.fullStringWithNewParam('baz', 'quux');
|
|
|
|
expect(result).toMatch(/foo=bar/);
|
|
expect(result).toMatch(/baz=quux/);
|
|
});
|
|
});
|
|
|
|
describe('#getParam', function() {
|
|
it('returns the value of the requested key', function() {
|
|
const windowLocation = {
|
|
search: '?baz=quux%20corge'
|
|
};
|
|
const queryString = new jasmineUnderTest.QueryString({
|
|
getWindowLocation: function() {
|
|
return windowLocation;
|
|
}
|
|
});
|
|
|
|
expect(queryString.getParam('baz')).toEqual('quux corge');
|
|
});
|
|
|
|
it('returns null if the key is not present', function() {
|
|
const windowLocation = {
|
|
search: ''
|
|
};
|
|
const queryString = new jasmineUnderTest.QueryString({
|
|
getWindowLocation: function() {
|
|
return windowLocation;
|
|
}
|
|
});
|
|
|
|
expect(queryString.getParam('baz')).toBeFalsy();
|
|
});
|
|
});
|
|
});
|