react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / http-browserify / test / request_url.js
80724 viewsglobal.window = global;1global.location = {2host: 'localhost:8081',3port: 8081,4protocol: 'http:'5};67var noop = function() {};8global.XMLHttpRequest = function() {9this.open = noop;10this.send = noop;11};1213global.FormData = function () {};14global.Blob = function () {};15global.ArrayBuffer = function () {};1617var test = require('tape').test;18var http = require('../index.js');192021test('Test simple url string', function(t) {22var url = { path: '/api/foo' };23var request = http.get(url, noop);2425t.equal( request.uri, 'http://localhost:8081/api/foo', 'Url should be correct');26t.end();2728});293031test('Test full url object', function(t) {32var url = {33host: "localhost:8081",34hostname: "localhost",35href: "http://localhost:8081/api/foo?bar=baz",36method: "GET",37path: "/api/foo?bar=baz",38pathname: "/api/foo",39port: "8081",40protocol: "http:",41query: "bar=baz",42search: "?bar=baz",43slashes: true44};4546var request = http.get(url, noop);4748t.equal( request.uri, 'http://localhost:8081/api/foo?bar=baz', 'Url should be correct');49t.end();5051});5253test('Test alt protocol', function(t) {54var params = {55protocol: "foo:",56hostname: "localhost",57port: "3000",58path: "/bar"59};6061var request = http.get(params, noop);6263t.equal( request.uri, 'foo://localhost:3000/bar', 'Url should be correct');64t.end();6566});6768test('Test string as parameters', function(t) {69var url = '/api/foo';70var request = http.get(url, noop);7172t.equal( request.uri, 'http://localhost:8081/api/foo', 'Url should be correct');73t.end();7475});7677test('Test withCredentials param', function(t) {78var url = '/api/foo';7980var request = http.request({ url: url, withCredentials: false }, noop);81t.equal( request.xhr.withCredentials, false, 'xhr.withCredentials should be false');8283var request = http.request({ url: url, withCredentials: true }, noop);84t.equal( request.xhr.withCredentials, true, 'xhr.withCredentials should be true');8586var request = http.request({ url: url }, noop);87t.equal( request.xhr.withCredentials, true, 'xhr.withCredentials should be true');8889t.end();90});9192test('Test POST XHR2 types', function(t) {93t.plan(3);94var url = '/api/foo';9596var request = http.request({ url: url, method: 'POST' }, noop);97request.xhr.send = function (data) {98t.ok(data instanceof global.ArrayBuffer, 'data should be instanceof ArrayBuffer');99};100request.end(new global.ArrayBuffer());101102request = http.request({ url: url, method: 'POST' }, noop);103request.xhr.send = function (data) {104t.ok(data instanceof global.Blob, 'data should be instanceof Blob');105};106request.end(new global.Blob());107108request = http.request({ url: url, method: 'POST' }, noop);109request.xhr.send = function (data) {110t.ok(data instanceof global.FormData, 'data should be instanceof FormData');111};112request.end(new global.FormData());113});114115116