-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
72 lines (63 loc) · 2.11 KB
/
Copy pathtest.js
File metadata and controls
72 lines (63 loc) · 2.11 KB
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
/* eslint-disable no-redeclare */
var expect = require('expect.js');
var parse = require('../src/index.js').parse;
var format = require('../src/index.js').format;
describe('单元测试', function () {
this.timeout(1000);
describe('parse', function () {
it('bad case', function () {
var a = parse('javascript: void');
expect(a.href).to.equal('javascript: void');
var a = parse('#');
expect(a.href).to.equal('#');
var a = parse('');
expect(a.href).to.equal('');
var a = parse('/a/b/c');
expect(a.href).to.equal('/a/b/c');
});
it('normal', function () {
var a = parse('http://user:pass@host.com:8080/p/a/t/h?query=string#hash');
expect(a.hash).to.equal('#hash');
expect(a.host).to.equal('host.com:8080');
expect(a.hostname).to.equal('host.com');
expect(a.href).to.equal(
'http://user:pass@host.com:8080/p/a/t/h?query=string#hash',
);
expect(a.origin).to.equal('http://user:pass@host.com:8080');
expect(a.path).to.equal('/p/a/t/h?query=string');
expect(a.pathname).to.equal('/p/a/t/h');
expect(a.port).to.equal('8080');
expect(a.protocol).to.equal('http:');
expect(a.query).to.equal('query=string');
expect(a.search).to.equal('?query=string');
});
it('parseQueryString', function () {
var a = parse(
'http://user:pass@host.com:8080/p/a/t/h?query=string#hash',
true,
);
expect(a.query.query).to.equal('string');
});
});
describe('format', function () {
it('normal', function () {
var a = format({
auth: 'user:pass',
hash: '#hash',
host: 'host.com:8080',
hostname: 'host.com',
href: 'http://user:pass@host.com:8080/p/a/t/h?query=string#hash',
origin: 'http://user:pass@host.com:8080',
path: '/p/a/t/h?query=string',
pathname: '/p/a/t/h',
port: '8080',
protocol: 'http:',
query: 'query=string',
search: '?query=string',
});
expect(a).to.equal(
'http://user:pass@host.com:8080/p/a/t/h?query=string#hash',
);
});
});
});