Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust specs to work with new lib interface #1351

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 0 additions & 46 deletions test/specs/__helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,49 +47,3 @@ getAjaxRequest = (function () {

return getAjaxRequest
})()

// Validate an invalid character error
validateInvalidCharacterError = function validateInvalidCharacterError (error) {
expect(/character/i.test(error.message)).toEqual(true)
}

// Setup basic auth tests
setupBasicAuthTest = function setupBasicAuthTest () {
beforeEach(function () {
jasmine.Ajax.install()
})

afterEach(function () {
jasmine.Ajax.uninstall()
})

it('should accept HTTP Basic auth with username/password', function (done) {
axios('/foo', {
auth: {
username: 'Aladdin',
password: 'open sesame'
}
})

setTimeout(function () {
const request = jasmine.Ajax.requests.mostRecent()

expect(request.requestHeaders['Authorization']).toEqual('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==')
done()
}, 100)
})

it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters', function (done) {
axios('/foo', {
auth: {
username: 'Aladßç£☃din',
password: 'open sesame'
}
}).then(function (response) {
done(new Error('Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.'))
}).catch(function (error) {
validateInvalidCharacterError(error)
done()
})
})
}
4 changes: 2 additions & 2 deletions test/specs/adapter.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const axios = require('../../index')
import axios from '../../index'

describe('adapter', function () {
it('should support custom adapter', function (done) {
let called = false

axios('/foo', {
axios.get('/foo', {
adapter: function (config) {
called = true
}
Expand Down
4 changes: 3 additions & 1 deletion test/specs/api.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import axios from '../../index'

describe('static api', function () {
it('should have request method helpers', function () {
expect(typeof axios.request).toEqual('function')
Expand All @@ -11,7 +13,7 @@ describe('static api', function () {
})

it('should have promise method helpers', function () {
const promise = axios()
const promise = axios.get()

expect(typeof promise.then).toEqual('function')
expect(typeof promise.catch).toEqual('function')
Expand Down
48 changes: 47 additions & 1 deletion test/specs/basicAuth.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
import axios from '../../lib/axios'

// Validate an invalid character error
function validateInvalidCharacterError (error) {
expect(/character/i.test(error.message)).toEqual(true)
}

describe('basicAuth without btoa polyfill', function () {
setupBasicAuthTest()
beforeEach(function () {
jasmine.Ajax.install()
})

afterEach(function () {
jasmine.Ajax.uninstall()
})

it('should accept HTTP Basic auth with username/password', function (done) {
axios.get('/foo', {
auth: {
username: 'Alibaba',
password: 'open sesame'
}
})

setTimeout(function () {
const request = jasmine.Ajax.requests.mostRecent()

// Aladdin cannot open the sesame
expect(request.requestHeaders['Authorization']).not.toEqual('Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==')
// Alibaba can open the sesame
expect(request.requestHeaders['Authorization']).toEqual('Basic QWxpYmFiYTpvcGVuIHNlc2FtZQ==')
done()
}, 100)
})

it('should fail to encode HTTP Basic auth credentials with non-Latin1 characters', function (done) {
axios.get('/foo', {
auth: {
username: 'Aladßç£☃din',
password: 'open sesame'
}
}).then(function (response) {
done(new Error('Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.'))
}).catch(function (error) {
validateInvalidCharacterError(error)
done()
})
})
})
19 changes: 0 additions & 19 deletions test/specs/basicAuthWithPolyfill.spec.js

This file was deleted.

5 changes: 3 additions & 2 deletions test/specs/cancel.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Cancel = axios.Cancel
const CancelToken = axios.CancelToken
/* global getAjaxRequest */

import axios, { Cancel, CancelToken } from '../../lib/axios'

describe('cancel', function () {
beforeEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/cancel/Cancel.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Cancel = require('../../../lib/cancel/Cancel')
import Cancel from '../../../lib/cancel/Cancel'

describe('Cancel', function () {
describe('toString', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/cancel/CancelToken.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const CancelToken = require('../../../lib/cancel/CancelToken')
const Cancel = require('../../../lib/cancel/Cancel')
import CancelToken from '../../../lib/cancel/CancelToken'
import Cancel from '../../../lib/cancel/Cancel'

describe('CancelToken', function () {
describe('constructor', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/cancel/isCancel.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const isCancel = require('../../../lib/cancel/isCancel')
const Cancel = require('../../../lib/cancel/Cancel')
import isCancel from '../../../lib/cancel/isCancel'
import Cancel from '../../../lib/cancel/Cancel'

describe('isCancel', function () {
it('returns true if value is a Cancel', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core/createError.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const createError = require('../../../lib/core/createError')
import createError from '../../../lib/core/createError'

describe('core::createError', function () {
it('should create an Error with message, config, code, request and response', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core/enhanceError.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const enhanceError = require('../../../lib/core/enhanceError')
import enhanceError from '../../../lib/core/enhanceError'

describe('core::enhanceError', function () {
it('should add config, config, request and response to error', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core/settle.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const settle = require('../../../lib/core/settle')
import settle from '../../../lib/core/settle'

describe('core::settle', function () {
let resolve
Expand Down
2 changes: 1 addition & 1 deletion test/specs/core/transformData.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const transformData = require('../../../lib/core/transformData')
import transformData from '../../../lib/core/transformData'

describe('core::transformData', function () {
it('should support a single transformer', function () {
Expand Down
13 changes: 8 additions & 5 deletions test/specs/defaults.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const defaults = require('../../lib/defaults')
const utils = require('../../lib/utils')
/* global getAjaxRequest */

import axios from '../../lib/axios'
import defaults from '../../lib/defaults'
import utils from '../../lib/utils'

describe('defaults', function () {
const XSRF_COOKIE_NAME = 'CUSTOM-XSRF-TOKEN'
Expand Down Expand Up @@ -36,7 +39,7 @@ describe('defaults', function () {
})

it('should use global defaults config', function (done) {
axios('/foo')
axios.get('/foo')

getAjaxRequest().then(function (request) {
expect(request.url).toBe('/foo')
Expand All @@ -47,7 +50,7 @@ describe('defaults', function () {
it('should use modified defaults config', function (done) {
axios.defaults.baseURL = 'http://example.com/'

axios('/foo')
axios.get('/foo')

getAjaxRequest().then(function (request) {
expect(request.url).toBe('http://example.com/foo')
Expand All @@ -56,7 +59,7 @@ describe('defaults', function () {
})

it('should use request config', function (done) {
axios('/foo', {
axios.get('/foo', {
baseURL: 'http://www.example.com'
})

Expand Down
5 changes: 4 additions & 1 deletion test/specs/headers.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* global getAjaxRequest */
import axios from '../../lib/axios'

function testHeaderValue (headers, key, val) {
let found = false

Expand Down Expand Up @@ -30,7 +33,7 @@ describe('headers', function () {
it('should default common headers', function (done) {
const headers = axios.defaults.headers.common

axios('/foo')
axios.get('/foo')

getAjaxRequest().then(function (request) {
for (const key in headers) {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/bind.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const bind = require('../../../lib/helpers/bind')
import bind from '../../../lib/helpers/bind'

describe('bind', function () {
it('should bind an object to a function', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/btoa.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const __btoa = require('../../../lib/helpers/btoa')
import __btoa from '../../../lib/helpers/btoa'

describe('btoa polyfill', function () {
it('should behave the same as native window.btoa', function () {
Expand Down
9 changes: 5 additions & 4 deletions test/specs/helpers/buildURL.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const buildURL = require('../../../lib/helpers/buildURL')
const URLSearchParams = require('url-search-params')
/* global sinon */
import buildURL from '../../../lib/helpers/buildURL'
import * as URLSearchParams from 'url-search-params'

describe('helpers::buildURL', function () {
it('should support null params', function () {
Expand Down Expand Up @@ -55,8 +56,8 @@ describe('helpers::buildURL', function () {
})

it('should use serializer if provided', function () {
serializer = sinon.stub()
params = {foo: 'bar'}
const serializer = sinon.stub()
const params = {foo: 'bar'}
serializer.returns('foo=bar')
expect(buildURL('/foo', params, serializer)).toEqual('/foo?foo=bar')
expect(serializer.calledOnce).toBe(true)
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/combineURLs.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const combineURLs = require('../../../lib/helpers/combineURLs')
import combineURLs from '../../../lib/helpers/combineURLs'

describe('helpers::combineURLs', function () {
it('should combine URLs', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/cookies.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const cookies = require('../../../lib/helpers/cookies')
import cookies from '../../../lib/helpers/cookies'

describe('helpers::cookies', function () {
afterEach(function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/isAbsoluteURL.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const isAbsoluteURL = require('../../../lib/helpers/isAbsoluteURL')
import isAbsoluteURL from '../../../lib/helpers/isAbsoluteURL'

describe('helpers::isAbsoluteURL', function () {
it('should return true if URL begins with valid scheme name', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/isURLSameOrigin.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const isURLSameOrigin = require('../../../lib/helpers/isURLSameOrigin')
import isURLSameOrigin from '../../../lib/helpers/isURLSameOrigin'

describe('helpers::isURLSameOrigin', function () {
it('should detect same origin', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/normalizeHeaderName.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const normalizeHeaderName = require('../../../lib/helpers/normalizeHeaderName')
import normalizeHeaderName from '../../../lib/helpers/normalizeHeaderName'

describe('helpers::normalizeHeaderName', function () {
it('should normalize matching header name', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/parseHeaders.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const parseHeaders = require('../../../lib/helpers/parseHeaders')
import parseHeaders from '../../../lib/helpers/parseHeaders'

describe('helpers::parseHeaders', function () {
it('should parse headers', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/specs/helpers/spread.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const spread = require('../../../lib/helpers/spread')
import spread from '../../../lib/helpers/spread'

describe('helpers::spread', function () {
it('should spread array to arguments', function () {
Expand Down
4 changes: 4 additions & 0 deletions test/specs/instance.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* global getAjaxRequest */

import axios from '../../index'

describe('instance', function () {
beforeEach(function () {
jasmine.Ajax.install()
Expand Down
4 changes: 4 additions & 0 deletions test/specs/interceptors.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* global getAjaxRequest */

import axios from '../../index'

describe('interceptors', function () {
beforeEach(function () {
jasmine.Ajax.install()
Expand Down
12 changes: 8 additions & 4 deletions test/specs/options.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/* global getAjaxRequest */

import axios from '../../index'

describe('options', function () {
beforeEach(function () {
jasmine.Ajax.install()
Expand All @@ -8,7 +12,7 @@ describe('options', function () {
})

it('should default method to get', function (done) {
axios('/foo')
axios.get('/foo')

getAjaxRequest().then(function (request) {
expect(request.method).toBe('GET')
Expand All @@ -17,7 +21,7 @@ describe('options', function () {
})

it('should accept headers', function (done) {
axios('/foo', {
axios.get('/foo', {
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
Expand All @@ -30,7 +34,7 @@ describe('options', function () {
})

it('should accept params', function (done) {
axios('/foo', {
axios.get('/foo', {
params: {
foo: 123,
bar: 456
Expand All @@ -44,7 +48,7 @@ describe('options', function () {
})

it('should allow overriding default headers', function (done) {
axios('/foo', {
axios.get('/foo', {
headers: {
'Accept': 'foo/bar'
}
Expand Down