forked from capricorn86/happy-dom
/
URL.test.ts
69 lines (66 loc) · 2.43 KB
/
URL.test.ts
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
import URL from '../../src/location/URL';
describe('URL', () => {
describe('constructor()', () => {
it('Parses "https://google.com/some-path/?key=value&key2=value2#hash".', () => {
const href = 'https://google.com/some-path/?key=value&key2=value2#hash';
const url = new URL(href);
expect(url.href).toBe(href);
expect(url.protocol).toBe('https:');
expect(url.hostname).toBe('google.com');
expect(url.port).toBe('');
expect(url.pathname).toBe('/some-path/');
expect(url.search).toBe('?key=value&key2=value2');
expect(url.hash).toBe('#hash');
expect(url.username).toBe('');
expect(url.password).toBe('');
expect(url.host).toBe('google.com');
expect(url.origin).toBe('https://google.com');
});
it('Parses "https://user:password@google.com/some-path/".', () => {
const href = 'https://user:password@google.com/some-path/';
const url = new URL(href);
expect(url.href).toBe(href);
expect(url.protocol).toBe('https:');
expect(url.hostname).toBe('google.com');
expect(url.port).toBe('');
expect(url.pathname).toBe('/some-path/');
expect(url.search).toBe('');
expect(url.hash).toBe('');
expect(url.username).toBe('user');
expect(url.password).toBe('password');
expect(url.host).toBe('google.com');
expect(url.origin).toBe('https://google.com');
});
it('Parses "https://google.com:8080/some-path/".', () => {
const href = 'https://google.com:8080/some-path/';
const url = new URL(href);
expect(url.href).toBe(href);
expect(url.protocol).toBe('https:');
expect(url.hostname).toBe('google.com');
expect(url.port).toBe('8080');
expect(url.pathname).toBe('/some-path/');
expect(url.search).toBe('');
expect(url.hash).toBe('');
expect(url.username).toBe('');
expect(url.password).toBe('');
expect(url.host).toBe('google.com:8080');
expect(url.origin).toBe('https://google.com:8080');
});
it('Parses "https://google.com".', () => {
const formatHref = 'https://google.com/';
const href = 'https://google.com';
const url = new URL(href);
expect(url.href).toBe(formatHref);
expect(url.protocol).toBe('https:');
expect(url.hostname).toBe('google.com');
expect(url.port).toBe('');
expect(url.pathname).toBe('/');
expect(url.search).toBe('');
expect(url.hash).toBe('');
expect(url.username).toBe('');
expect(url.password).toBe('');
expect(url.host).toBe('google.com');
expect(url.origin).toBe('https://google.com');
});
});
});