|
| 1 | +import test from 'ava'; |
| 2 | +import queryString from '..'; |
| 3 | + |
| 4 | +test('stringify URL without a query string', t => { |
| 5 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/'}), 'https://foo.bar/'); |
| 6 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/', query: {}}), 'https://foo.bar/'); |
| 7 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/#top', query: {}}), 'https://foo.bar/#top'); |
| 8 | + t.deepEqual(queryString.stringifyUrl({url: '', query: {}}), ''); |
| 9 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar?', query: {}}), 'https://foo.bar'); |
| 10 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar?foo=bar', query: {}}), 'https://foo.bar?foo=bar'); |
| 11 | +}); |
| 12 | + |
| 13 | +test('stringify URL with a query string', t => { |
| 14 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}}), 'https://foo.bar?foo=bar'); |
| 15 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar?', query: {foo: 'bar'}}), 'https://foo.bar?foo=bar'); |
| 16 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar/#top', query: {foo: 'bar'}}), 'https://foo.bar/?foo=bar#top'); |
| 17 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar', a: 'b'}}), 'https://foo.bar?a=b&foo=bar'); |
| 18 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar?a=b', query: {foo: ['bar', 'baz']}}), 'https://foo.bar?a=b&foo=bar&foo=baz'); |
| 19 | + t.deepEqual(queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}}), 'https://foo.bar?foo=bar'); |
| 20 | +}); |
| 21 | + |
| 22 | +test('stringify URL from the result of `parseUrl` without query string', t => { |
| 23 | + const url = 'https://foo.bar'; |
| 24 | + const parsedUrl = queryString.parseUrl(url); |
| 25 | + t.deepEqual(queryString.stringifyUrl(parsedUrl), url); |
| 26 | +}); |
| 27 | + |
| 28 | +test('stringify URL from the result of `parseUrl` with query string', t => { |
| 29 | + const url = 'https://foo.bar?foo=bar&foo=baz'; |
| 30 | + const parsedUrl = queryString.parseUrl(url); |
| 31 | + t.deepEqual(queryString.stringifyUrl(parsedUrl), url); |
| 32 | +}); |
| 33 | + |
| 34 | +test('stringify URL from the result of `parseUrl` with query string that contains `=`', t => { |
| 35 | + const url = 'https://foo.bar?foo=bar=&foo=baz='; |
| 36 | + const parsedUrl = queryString.parseUrl(url); |
| 37 | + t.deepEqual(queryString.stringifyUrl(parsedUrl, {encode: false}), url); |
| 38 | +}); |
0 commit comments