/
index.js
110 lines (77 loc) · 2.94 KB
/
index.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
'use strict';
const chai = require('chai');
const expect = chai.expect;
chai.use(require('..'));
describe('chai-url', () => {
describe('path', () => {
it('matches paths on urls', () => {
expect('http://example.com/foo/bar').to.have.path('/foo/bar');
});
it('does not match partial paths', () => {
expect('http://example.com/foo/bar').not.to.have.path('/foo');
});
it('matches partial paths on urls if `contain` flag is present', () => {
expect('http://example.com/foo/bar').to.contain.path('/foo');
});
});
describe('hostname', () => {
it('matches hostnames', () => {
expect('http://example.com/foo/bar').to.have.hostname('example.com');
expect('http://www.example.com/foo/bar').to.have.hostname('www.example.com');
});
it('does not match partial hostnames', () => {
expect('http://www.example.com/foo/bar').not.to.have.hostname('example.com');
});
it('matches partial hostname on urls if `contain` flag is present', () => {
expect('http://www.example.com/foo/bar').to.contain.hostname('example.com');
});
it('handles domain-less urls', () => {
expect('/foo/bar').not.to.have.hostname();
});
});
describe('protocol', () => {
it('matches protocol', () => {
expect('http://example.com/foo/bar').to.have.protocol('http');
});
it('doesn\'t matter if expected protocol has trailing : or not', () => {
expect('http://example.com/foo/bar').to.have.protocol('http');
expect('http://example.com/foo/bar').to.have.protocol('http:');
});
it('handles protocol-less urls', () => {
expect('//example.com/foo/bar').not.to.have.protocol();
});
});
describe('auth', () => {
it('matches auth segment of urls', () => {
expect('http://user:pass@example.com/foo/bar').to.have.auth('user:pass');
});
it('handles auth-less urls', () => {
expect('http://example.com/foo/bar').not.to.have.auth();
});
});
describe('hash', () => {
it('matches hash segment of urls', () => {
expect('http://example.com/foo/bar#section').to.have.hash('section');
expect('#section').to.have.hash('section');
});
it('ignores leading # symbol', () => {
expect('http://example.com/foo/bar#section').to.have.hash('section');
expect('http://example.com/foo/bar#section').to.have.hash('#section');
});
it('handles hash-less urls', () => {
expect('http://example.com/foo/bar').not.to.have.hash();
});
});
describe('port', () => {
it('matches port segment of urls', () => {
expect('http://example.com:3000/').to.have.port(3000);
});
it('handles both string and numerical values', () => {
expect('http://example.com:3000/foo/bar').to.have.port(3000);
expect('http://example.com:3000/foo/bar').to.have.port('3000');
});
it('handles port-less urls', () => {
expect('http://example.com/foo/bar').not.to.have.port();
});
});
});