Syntax previewClick to edit
1234
export default function parseQueryString(qs) {
throw new Error('Not implemented');
}
Syntax previewClick to edit
1234567891011121314151617181920212223242526272829303132333435
import parseQueryString from './file';
describe('parseQueryString', () => {
test('parses basic key-value pairs', () => {
expect(parseQueryString('?a=1&b=two')).toEqual({ a: '1', b: 'two' });
});
test('treats + as space and decodes percent-encoding', () => {
expect(parseQueryString('q=hello+world')).toEqual({ q: 'hello world' });
expect(parseQueryString('a=%26')).toEqual({ a: '&' });
});
test('keeps the last value when keys repeat', () => {
expect(parseQueryString('a=1&a=2&a=3')).toEqual({ a: '3' });
});
test('missing = means empty string value', () => {
expect(parseQueryString('flag')).toEqual({ flag: '' });
expect(parseQueryString('flag&x=1')).toEqual({ flag: '', x: '1' });
});
test('ignores empty keys and empty parts', () => {
expect(parseQueryString('=x&&y=1&')).toEqual({ y: '1' });
});
test('does not break on malformed encoding (keeps raw)', () => {
expect(parseQueryString('a=%E0%A4')).toEqual({ a: '%E0%A4' });
});
test('empty input returns {}', () => {
expect(parseQueryString('')).toEqual({});
expect(parseQueryString('?')).toEqual({});
});
});
Run tests to see results.