Skip to content

Commit 487c6f7

Browse files
committed
moved from jasmine to mocha for tests
1 parent f61619d commit 487c6f7

9 files changed

+526
-540
lines changed

.travis.yml

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
language: node_js
22
node_js:
33
- "0.10"
4-
before_script:
5-
- npm install -g jake

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
],
2424
"main": "Uri",
2525
"scripts": {
26-
"test": "jake test"
26+
"test": "./node_modules/.bin/mocha"
2727
},
2828
"dependencies": {},
2929
"devDependencies": {
30-
"jasmine-node": "~1.11.0",
3130
"jshint": "~2.1.11",
32-
"uglify-js": "~2.4.0"
31+
"uglify-js": "~2.4.0",
32+
"mocha": "~1.14.0",
33+
"chai": "~1.8.1"
3334
},
3435
"optionalDependencies": {},
3536
"engines": {

spec/Uri.spec.js

-492
This file was deleted.

spec/runner.html

-43
This file was deleted.

test/mocha.opts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--recursive
2+
-R spec

test/uri.js

+182
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
var expect = require('chai').expect
2+
3+
var Uri = (typeof(require) === 'function') ? require('../Uri') : window.Uri
4+
5+
describe('Uri', function() {
6+
var u
7+
8+
beforeEach(function() {
9+
u = new Uri('http://test.com')
10+
})
11+
12+
it('can replace protocol', function() {
13+
u.protocol('https')
14+
expect(u.toString()).to.equal('https://test.com')
15+
})
16+
17+
it('can replace protocol with colon suffix', function() {
18+
u.protocol('https:')
19+
expect(u.toString()).to.equal('https://test.com')
20+
})
21+
22+
it('keeps authority prefix when protocol is removed', function() {
23+
u.protocol(null)
24+
expect(u.toString()).to.equal('//test.com')
25+
})
26+
27+
it('can disable authority prefix but keep protocol', function() {
28+
u.hasAuthorityPrefix(false)
29+
expect(u.toString()).to.equal('http://test.com')
30+
})
31+
32+
it('can add user info', function() {
33+
u.userInfo('username:password')
34+
expect(u.toString()).to.equal('http://username:password@test.com')
35+
})
36+
37+
it('can add user info with trailing at', function() {
38+
u.userInfo('username:password@')
39+
expect(u.toString()).to.equal('http://username:password@test.com')
40+
})
41+
42+
it('can add a hostname to a relative path', function() {
43+
u = new Uri('/index.html')
44+
u.host('wherever.com')
45+
expect(u.toString()).to.equal('wherever.com/index.html')
46+
})
47+
48+
it('can change a hostname ', function() {
49+
u.host('wherever.com')
50+
expect(u.toString()).to.equal('http://wherever.com')
51+
})
52+
53+
it('should not add a port when there is no hostname', function() {
54+
u = new Uri('/index.html')
55+
u.port(8080)
56+
expect(u.toString()).to.equal('/index.html')
57+
})
58+
59+
it('should be able to change the port', function() {
60+
u.port(8080)
61+
expect(u.toString()).to.equal('http://test.com:8080')
62+
})
63+
64+
it('should be able to add a path to a domain', function() {
65+
u = new Uri('test.com')
66+
u.path('/some/article.html')
67+
expect(u.toString()).to.equal('test.com/some/article.html')
68+
})
69+
70+
it('should be able to change a path', function() {
71+
u.path('/some/article.html')
72+
expect(u.toString()).to.equal('http://test.com/some/article.html')
73+
})
74+
75+
it('should be able to delete a path', function() {
76+
u = new Uri('http://test.com/index.html')
77+
u.path(null)
78+
expect(u.toString()).to.equal('http://test.com')
79+
})
80+
81+
it('should be able to empty a path', function() {
82+
u = new Uri('http://test.com/index.html')
83+
u.path('')
84+
expect(u.toString()).to.equal('http://test.com')
85+
})
86+
87+
it('should be able to add a query to nothing', function() {
88+
u = new Uri('')
89+
u.query('this=that&something=else')
90+
expect(u.toString()).to.equal('?this=that&something=else')
91+
})
92+
93+
it('should be able to add a query to a relative path', function() {
94+
u = new Uri('/some/file.html')
95+
u.query('this=that&something=else')
96+
expect(u.toString()).to.equal('/some/file.html?this=that&something=else')
97+
})
98+
99+
it('should be able to add a query to a domain', function() {
100+
u = new Uri('test.com')
101+
u.query('this=that&something=else')
102+
expect(u.toString()).to.equal('test.com/?this=that&something=else')
103+
})
104+
105+
it('should be able to swap a query', function() {
106+
u = new Uri('www.test.com?this=that&a=1&b=2c=3')
107+
u.query('this=that&something=else')
108+
expect(u.toString()).to.equal('www.test.com/?this=that&something=else')
109+
})
110+
111+
it('should be able to delete a query', function() {
112+
u = new Uri('www.test.com?this=that&a=1&b=2c=3')
113+
u.query(null)
114+
expect(u.toString()).to.equal('www.test.com')
115+
})
116+
117+
it('should be able to empty a query', function() {
118+
u = new Uri('www.test.com?this=that&a=1&b=2c=3')
119+
u.query('')
120+
expect(u.toString()).to.equal('www.test.com')
121+
})
122+
123+
it('should be able to add an anchor to a domain', function() {
124+
u = new Uri('test.com')
125+
u.anchor('content')
126+
expect(u.toString()).to.equal('test.com/#content')
127+
})
128+
129+
it('should be able to add an anchor with a hash prefix to a domain', function() {
130+
u = new Uri('test.com')
131+
u.anchor('#content')
132+
expect(u.toString()).to.equal('test.com/#content')
133+
})
134+
135+
it('should be able to add an anchor to a path', function() {
136+
u = new Uri('a/b/c/123.html')
137+
u.anchor('content')
138+
expect(u.toString()).to.equal('a/b/c/123.html#content')
139+
})
140+
141+
it('should be able to change an anchor', function() {
142+
u = new Uri('/a/b/c/index.html#content')
143+
u.anchor('about')
144+
expect(u.toString()).to.equal('/a/b/c/index.html#about')
145+
})
146+
147+
it('should be able to empty an anchor', function() {
148+
u = new Uri('/a/b/c/index.html#content')
149+
u.anchor('')
150+
expect(u.toString()).to.equal('/a/b/c/index.html')
151+
})
152+
153+
it('should be able to delete an anchor', function() {
154+
u = new Uri('/a/b/c/index.html#content')
155+
u.anchor(null)
156+
expect(u.toString()).to.equal('/a/b/c/index.html')
157+
})
158+
159+
it('should insert missing slash when origin and path have no slash', function () {
160+
u = new Uri('http://test.com')
161+
u.setPath('relativePath')
162+
expect(u.toString()).to.equal('http://test.com/relativePath')
163+
})
164+
165+
it('should remove extra slash when origin and path both provide a slash', function () {
166+
u = new Uri('http://test.com/')
167+
u.setPath('/relativePath')
168+
expect(u.toString()).to.equal('http://test.com/relativePath')
169+
})
170+
171+
it('should remove extra slashes when origin and path both provide too many slashes', function () {
172+
u = new Uri('http://test.com//')
173+
u.setPath('//relativePath')
174+
expect(u.toString()).to.equal('http://test.com/relativePath')
175+
})
176+
177+
it('should be able to clone a separate copy which does not share state', function() {
178+
var a = new Uri('?a=1'),
179+
b = a.clone().addQueryParam('b', '2')
180+
expect(a.toString()).to.not.equal(b.toString())
181+
})
182+
})

test/uri/fluent-setters.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
var expect = require('chai').expect
2+
3+
var Uri = (typeof(require) === 'function') ? require('../../Uri') : window.Uri
4+
5+
describe('Uri', function() {
6+
describe('fluent setters', function() {
7+
var u
8+
9+
it('can fluently add a path and anchor', function() {
10+
u = new Uri('www.yahoo.com')
11+
.setPath('/index.html')
12+
.setAnchor('content')
13+
expect(u.toString()).to.equal('www.yahoo.com/index.html#content')
14+
})
15+
16+
it('can fluently replace host and protocol', function() {
17+
u = new Uri('www.yahoo.com/index.html')
18+
.setHost('test.com')
19+
.setProtocol('https')
20+
expect(u.toString()).to.equal('https://test.com/index.html')
21+
})
22+
23+
it('can fluently construct a url out of nothing', function() {
24+
u = new Uri()
25+
.setPath('/index.html')
26+
.setAnchor('content')
27+
.setHost('www.test.com')
28+
.setPort(8080)
29+
.setUserInfo('username:password')
30+
.setProtocol('https')
31+
.setQuery('this=that&some=thing')
32+
expect(u.toString()).to.equal('https://username:password@www.test.com:8080/index.html?this=that&some=thing#content')
33+
})
34+
35+
it('can fluently destroy all parts of a url', function() {
36+
u = new Uri('https://username:password@www.test.com:8080/index.html?this=that&some=thing#content')
37+
.setPath(null)
38+
.setAnchor(null)
39+
.setHost(null)
40+
.setPort(null)
41+
.setUserInfo(null)
42+
.setProtocol(null)
43+
.setQuery(null)
44+
expect(u.toString()).to.equal('')
45+
})
46+
})
47+
})

0 commit comments

Comments
 (0)