tests.js
1.95 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
var urljoin = require('../lib/url-join');
describe('url join', function () {
it('should work for simple case', function () {
urljoin('http://www.google.com/', 'foo/bar', '?test=123')
.should.eql('http://www.google.com/foo/bar?test=123');
});
it('should work for simple case with new syntax', function () {
urljoin(['http://www.google.com/', 'foo/bar', '?test=123'])
.should.eql('http://www.google.com/foo/bar?test=123');
});
it('should work for hashbang urls', function () {
urljoin(['http://www.google.com', '#!', 'foo/bar', '?test=123'])
.should.eql('http://www.google.com/#!/foo/bar?test=123');
});
it('should be able to join protocol', function () {
urljoin('http:', 'www.google.com/', 'foo/bar', '?test=123')
.should.eql('http://www.google.com/foo/bar?test=123');
});
it('should be able to join protocol with slashes', function () {
urljoin('http://', 'www.google.com/', 'foo/bar', '?test=123')
.should.eql('http://www.google.com/foo/bar?test=123');
});
it('should remove extra slashes', function () {
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123')
.should.eql('http://www.google.com/foo/bar?test=123');
});
it('should support anchors in urls', function () {
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '#faaaaa')
.should.eql('http://www.google.com/foo/bar?test=123#faaaaa');
});
it('should support protocol-relative urls', function () {
urljoin('//www.google.com', 'foo/bar', '?test=123')
.should.eql('//www.google.com/foo/bar?test=123')
});
it('should merge multiple query params properly', function () {
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?key=456')
.should.eql('http://www.google.com/foo/bar?test=123&key=456');
urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '?boom=value', '&key=456')
.should.eql('http://www.google.com/foo/bar?test=123&boom=value&key=456');
});
});