Skip to content

Commit b0049fe

Browse files
author
James Halliday
committed
picked the test manually out of issues/#28
1 parent c4fbf36 commit b0049fe

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/request_url.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
global.window = {
2+
location: {
3+
host: 'localhost:8081',
4+
port: 8081,
5+
protocol: 'http:'
6+
}
7+
};
8+
9+
var noop = function() {};
10+
global.window.XMLHttpRequest = function() {
11+
this.open = noop;
12+
this.send = noop;
13+
};
14+
15+
var test = require('tape').test;
16+
var http = require('../index.js');
17+
18+
19+
test('Test simple url string', function(t) {
20+
var url = { path: '/api/foo' };
21+
var request = http.get(url, noop);
22+
23+
t.equal( request.uri, 'http://localhost:8081/api/foo', 'Url should be correct');
24+
t.end();
25+
26+
});
27+
28+
29+
test('Test full url object', function(t) {
30+
var url = {
31+
host: "localhost:8081",
32+
hostname: "localhost",
33+
href: "http://localhost:8081/api/foo?bar=baz",
34+
method: "GET",
35+
path: "/api/foo?bar=baz",
36+
pathname: "/api/foo",
37+
port: "8081",
38+
protocol: "http:",
39+
query: "bar=baz",
40+
search: "?bar=baz",
41+
slashes: true
42+
};
43+
44+
var request = http.get(url, noop);
45+
46+
t.equal( request.uri, 'http://localhost:8081/api/foo?bar=baz', 'Url should be correct');
47+
t.end();
48+
49+
});

0 commit comments

Comments
 (0)