UNPKG

1.99 kBJavaScriptView Raw
1var assert = require('assert');
2var Url = require('../lib/Url');
3
4describe('Url', function() {
5
6 describe('new Url()', function() {
7
8 it('should create a new instance with a URL', function() {
9 var url = new Url('http://www.google.com');
10 });
11
12 it('should create a new instance with no URL', function() {
13 var url = new Url();
14 });
15
16 });
17
18 describe('.getQuery()', function() {
19
20 it('should return a dictionary when I don\'t pass a parameter name', function() {
21 var url = new Url('http://www.google.com?page=first');
22 assert.deepEqual(url.getQuery(), {page: 'first'});
23 });
24
25 it('should return a value when I pass a parameter name', function() {
26 var url = new Url('http://localhost/?letters=abc');
27 assert.equal(url.getQuery('letters'), 'abc');
28 });
29
30 it('should return undefined when the query parameter isn\'t found', function() {
31 var url = new Url('http://localhost/?letters=abc');
32 assert.equal(url.getQuery('foobar'), undefined);
33 });
34
35 it('should return the default value when the query parameter isn\'t found', function() {
36 var url = new Url('http://localhost/?letters');
37 assert.equal(url.getQuery('letters', '123'), '123');
38 });
39
40 });
41
42 describe('.setQuery()', function() {
43
44 it('should replace the dictionary when I don\'t pass a parameter name', function() {
45 var url = new Url('http://localhost/?letters=abc');
46 url.setQuery({'foobar': 'power'});
47 assert.deepEqual(url.getQuery(), {'foobar': 'power'});
48 });
49
50 it('should replace the param when I pass a parameter name and value', function() {
51 var url = new Url('http://localhost/?letters=abc');
52 url.setQuery('letters', '123');
53 assert.equal(url.getQuery('letters'), 123);
54 });
55
56 });
57
58 describe('.toString()', function() {
59
60 it('should convert the URL to a string representation of the URL', function() {
61
62 var url = new Url('http://www.digitaledgeit.com.au/contact');
63
64 assert.equal(
65 'http://www.digitaledgeit.com.au/contact',
66 url.toString()
67 );
68
69 });
70
71 });
72
73});