Skip to content

Instantly share code, notes, and snippets.

@amyboyd
Created September 22, 2014 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amyboyd/68a86fe3f65a77fcfc7f to your computer and use it in GitHub Desktop.
Save amyboyd/68a86fe3f65a77fcfc7f to your computer and use it in GitHub Desktop.
// http://stackoverflow.com/a/13419367/224004
describe('parseQuery', function() {
it('parses a simple query string that starts with a ?', function() {
expect(parseQuery('?a=z')).toEqual({'a': 'z'});
});
it('parses a simple query string that doesn\'t start with a ?', function() {
expect(parseQuery('a=z')).toEqual({'a': 'z'});
});
it('decodes entities', function() {
expect(parseQuery('%5Ba%5D%20(%20v%20)=%5Ba%5D%20(%20v%20)')).toEqual({'[a] ( v )': '[a] ( v )'});
});
it('parses a query string with multiple values', function() {
expect(parseQuery('%5B=2&2=3')).toEqual({'[': '2', '2': '3'});
});
it('uses the last key value if there are duplicate keys', function() {
expect(parseQuery('?a=1&a=2&a=3&b=2&b=1')).toEqual({'a': '3', 'b': '1'});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment