提交 ede39aae 编写于 作者: M mzabriskie

Adding tests for transformers

上级 e3308899
describe('transform', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
it('should transform JSON to string', function () {
var data = {
foo: 'bar'
};
axios({
url: '/foo',
method: 'post',
data: data
});
var request = jasmine.Ajax.requests.mostRecent();
expect(request.params).toEqual('{"foo":"bar"}');
});
it('should override default transform', function () {
var data = {
foo: 'bar'
};
axios({
url: '/foo',
method: 'post',
data: data,
transformRequest: function (data) {
return data;
}
});
var request = jasmine.Ajax.requests.mostRecent();
expect(typeof request.params).toEqual('object');
});
it('should allow an Array of transformers', function () {
var data = {
foo: 'bar'
};
axios({
url: '/foo',
method: 'post',
data: data,
transformRequest: axios.defaults.transformRequest.concat(
function (data) {
return data.replace('bar', 'baz');
}
)
});
var request = jasmine.Ajax.requests.mostRecent();
expect(request.params).toEqual('{"foo":"baz"}');
});
it('should allowing mutating headers', function () {
var token = Math.floor(Math.random() * Math.pow(2, 64)).toString(36);
axios({
url: '/foo',
transformRequest: function (data, headers) {
headers['X-Authorization'] = token;
}
});
var request = jasmine.Ajax.requests.mostRecent();
expect(request.requestHeaders['X-Authorization']).toEqual(token);
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册