2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/test/specs/promise.spec.js
T
Jay ef3711d1b3 feat: implement prettier and fix all issues (#7385)
* feat: implement prettier and fix all issues

* fix: failing tests

* fix: implement feedback from codel, ai etc

* chore: dont throw in trim function

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix: incorrect fix

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-02-14 16:59:48 +02:00

74 lines
1.6 KiB
JavaScript

describe('promise', function () {
beforeEach(function () {
jasmine.Ajax.install();
});
afterEach(function () {
jasmine.Ajax.uninstall();
});
it('should provide succinct object to then', function (done) {
let response;
axios('/foo').then(function (r) {
response = r;
});
getAjaxRequest().then(function (request) {
request.respondWith({
status: 200,
responseText: '{"hello":"world"}',
});
setTimeout(function () {
expect(typeof response).toEqual('object');
expect(response.data.hello).toEqual('world');
expect(response.status).toEqual(200);
expect(response.headers['content-type']).toEqual('application/json');
expect(response.config.url).toEqual('/foo');
done();
}, 100);
});
});
it('should support all', function (done) {
let fulfilled = false;
axios.all([true, 123]).then(function () {
fulfilled = true;
});
setTimeout(function () {
expect(fulfilled).toEqual(true);
done();
}, 100);
});
it('should support spread', function (done) {
let sum = 0;
let fulfilled = false;
let result;
axios
.all([123, 456])
.then(
axios.spread(function (a, b) {
sum = a + b;
fulfilled = true;
return 'hello world';
})
)
.then(function (res) {
result = res;
})
.catch(done);
setTimeout(function () {
expect(fulfilled).toEqual(true);
expect(sum).toEqual(123 + 456);
expect(result).toEqual('hello world');
done();
}, 100);
});
});