2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-11 18:02:32 +03:00

Making isURLSameOrigin/cookies safe to use in all envs

This commit is contained in:
Matt Zabriskie
2015-11-19 15:18:47 -07:00
parent affe3aaa9a
commit 3d65057d71
9 changed files with 139 additions and 119 deletions
+11 -11
View File
@@ -1,18 +1,18 @@
var buildUrl = require('../../../lib/helpers/buildUrl');
var buildURL = require('../../../lib/helpers/buildURL');
describe('helpers::buildUrl', function () {
describe('helpers::buildURL', function () {
it('should support null params', function () {
expect(buildUrl('/foo')).toEqual('/foo');
expect(buildURL('/foo')).toEqual('/foo');
});
it('should support params', function () {
expect(buildUrl('/foo', {
expect(buildURL('/foo', {
foo: 'bar'
})).toEqual('/foo?foo=bar');
});
it('should support object params', function () {
expect(buildUrl('/foo', {
expect(buildURL('/foo', {
foo: {
bar: 'baz'
}
@@ -22,31 +22,31 @@ describe('helpers::buildUrl', function () {
it('should support date params', function () {
var date = new Date();
expect(buildUrl('/foo', {
expect(buildURL('/foo', {
date: date
})).toEqual('/foo?date=' + date.toISOString());
});
it('should support array params', function () {
expect(buildUrl('/foo', {
expect(buildURL('/foo', {
foo: ['bar', 'baz']
})).toEqual('/foo?foo[]=bar&foo[]=baz');
});
it('should support special char params', function () {
expect(buildUrl('/foo', {
expect(buildURL('/foo', {
foo: '@:$, '
})).toEqual('/foo?foo=@:$,+');
});
it('should support existing params', function () {
expect(buildUrl('/foo?foo=bar', {
expect(buildURL('/foo?foo=bar', {
bar: 'baz'
})).toEqual('/foo?foo=bar&bar=baz');
});
it('should support "length" parameter', function () {
expect(buildUrl('/foo', {
expect(buildURL('/foo', {
query: 'bar',
start: 0,
length: 5
@@ -57,7 +57,7 @@ describe('helpers::buildUrl', function () {
serializer = sinon.stub();
params = {foo: 'bar'};
serializer.returns('foo=bar');
expect(buildUrl('/foo', params, serializer)).toEqual('/foo?foo=bar');
expect(buildURL('/foo', params, serializer)).toEqual('/foo?foo=bar');
expect(serializer.calledOnce).toBe(true);
expect(serializer.calledWith(params)).toBe(true);
})
@@ -0,0 +1,11 @@
var isURLSameOrigin = require('../../../lib/helpers/isURLSameOrigin');
describe('helpers::isURLSameOrigin', function () {
it('should detect same origin', function () {
expect(isURLSameOrigin(window.location.href)).toEqual(true);
});
it('should detect different origin', function () {
expect(isURLSameOrigin('https://github.com/mzabriskie/axios')).toEqual(false);
});
});
@@ -1,11 +0,0 @@
var urlIsSameOrigin = require('../../../lib/helpers/urlIsSameOrigin');
describe('helpers::urlIsSameOrigin', function () {
it('should detect same origin', function () {
expect(urlIsSameOrigin(window.location.href)).toEqual(true);
});
it('should detect different origin', function () {
expect(urlIsSameOrigin('https://github.com/mzabriskie/axios')).toEqual(false);
});
});