UNPKG

1.71 kBJavaScriptView Raw
1/* eslint-env mocha */
2
3var expandUrl = require('../expandUrl')
4var chai = require('chai')
5var expect = chai.expect
6
7describe('expandUrl', function () {
8 it('overrides existing params', function () {
9 var url = expandUrl('https://example.com/?existing=asdf', { newparam: 'fdsa' })
10 expect(url).to.equal('https://example.com/?existing=asdf&newparam=fdsa')
11 })
12
13 it('replaces simple path params encoding as necessary', function () {
14 var url = expandUrl('https://example.com/path/:param/file', { param: 'one/two' })
15 expect(url).to.equal('https://example.com/path/one%2Ftwo/file')
16 })
17
18 it('throws an error when a simple path param is missing', function () {
19 expect(function () { expandUrl('https://example.com/path/:param/file', {}) }).to.throw('No value for :param')
20 })
21
22 it('replaces full path params', function () {
23 var url = expandUrl('https://example.com/path/:param*/file', { param: 'one/two' })
24 expect(url).to.equal('https://example.com/path/one/two/file')
25 })
26
27 it('throws an error when a full path param is missing', function () {
28 expect(function () { expandUrl('https://example.com/path/:param*/file', {}) }).to.throw('No value for :param*')
29 })
30
31 it('maintains hash', function () {
32 var url = expandUrl('https://example.com/path#hash', {})
33 expect(url).to.equal('https://example.com/path#hash')
34 })
35
36 it('maintains port', function () {
37 var url = expandUrl('https://example.com:1234/path', {})
38 expect(url).to.equal('https://example.com:1234/path')
39 })
40
41 it('maintains password', function () {
42 var url = expandUrl('https://user:pass@example.com:1234/path', {})
43 expect(url).to.equal('https://user:pass@example.com:1234/path')
44 })
45})