forked from prebid/Prebid.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_spec.js
94 lines (77 loc) · 2.7 KB
/
url_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import {format, parse} from '../../src/url';
import { expect } from 'chai';
describe('helpers.url', function () {
describe('parse()', function () {
let parsed;
beforeEach(function () {
parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash');
});
it('extracts the protocol', function () {
expect(parsed).to.have.property('protocol', 'http');
});
it('extracts the hostname', function () {
expect(parsed).to.have.property('hostname', 'example.com');
});
it('extracts the port', function () {
expect(parsed).to.have.property('port', 3000);
});
it('extracts the pathname', function () {
expect(parsed).to.have.property('pathname', '/pathname/');
});
it('extracts the search query', function () {
expect(parsed).to.have.property('search');
expect(parsed.search).to.eql({
foo: 'xxx',
search: 'test',
bar: 'foo',
});
});
it('extracts the hash', function () {
expect(parsed).to.have.property('hash', 'hash');
});
it('extracts the host', function () {
expect(parsed).to.have.property('host', 'example.com:3000');
});
});
describe('parse(url, {noDecodeWholeURL: true})', function () {
let parsed;
beforeEach(function () {
parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash', {noDecodeWholeURL: true});
});
it('extracts the search query', function () {
expect(parsed).to.have.property('search');
expect(parsed.search).to.eql({
foo: 'bar',
search: 'test',
bar: 'foo%26foo%3Dxxx',
});
});
});
describe('format()', function () {
it('formats an object in to a URL', function () {
expect(format({
protocol: 'http',
hostname: 'example.com',
port: 3000,
pathname: '/pathname/',
search: {foo: 'bar', search: 'test', bar: 'foo%26foo%3Dxxx'},
hash: 'hash'
})).to.equal('http://example.com:3000/pathname/?foo=bar&search=test&bar=foo%26foo%3Dxxx#hash');
});
it('will use defaults for missing properties', function () {
expect(format({
hostname: 'example.com'
})).to.equal('http://example.com');
});
});
describe('parse(url, {decodeSearchAsString: true})', function () {
let parsed;
beforeEach(function () {
parsed = parse('http://example.com:3000/pathname/?search=test&foo=bar&bar=foo%26foo%3Dxxx#hash', {decodeSearchAsString: true});
});
it('extracts the search query', function () {
expect(parsed).to.have.property('search');
expect(parsed.search).to.equal('?search=test&foo=bar&bar=foo&foo=xxx');
});
});
});