mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
ef3711d1b3
* 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>
112 lines
3.1 KiB
JavaScript
112 lines
3.1 KiB
JavaScript
describe('progress events', function () {
|
|
beforeEach(function () {
|
|
jasmine.Ajax.install();
|
|
});
|
|
|
|
afterEach(function () {
|
|
jasmine.Ajax.uninstall();
|
|
});
|
|
|
|
it('should add a download progress handler', function (done) {
|
|
const progressSpy = jasmine.createSpy('progress');
|
|
|
|
axios('/foo', { onDownloadProgress: progressSpy });
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
request.respondWith({
|
|
status: 200,
|
|
responseText: '{"foo": "bar"}',
|
|
});
|
|
expect(progressSpy).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should add a upload progress handler', function (done) {
|
|
const progressSpy = jasmine.createSpy('progress');
|
|
|
|
axios('/foo', { onUploadProgress: progressSpy });
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
// Jasmine AJAX doesn't trigger upload events. Waiting for upstream fix
|
|
// expect(progressSpy).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should add both upload and download progress handlers', function (done) {
|
|
const downloadProgressSpy = jasmine.createSpy('downloadProgress');
|
|
const uploadProgressSpy = jasmine.createSpy('uploadProgress');
|
|
|
|
axios('/foo', { onDownloadProgress: downloadProgressSpy, onUploadProgress: uploadProgressSpy });
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
// expect(uploadProgressSpy).toHaveBeenCalled();
|
|
expect(downloadProgressSpy).not.toHaveBeenCalled();
|
|
request.respondWith({
|
|
status: 200,
|
|
responseText: '{"foo": "bar"}',
|
|
});
|
|
expect(downloadProgressSpy).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should add a download progress handler from instance config', function (done) {
|
|
const progressSpy = jasmine.createSpy('progress');
|
|
|
|
const instance = axios.create({
|
|
onDownloadProgress: progressSpy,
|
|
});
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
request.respondWith({
|
|
status: 200,
|
|
responseText: '{"foo": "bar"}',
|
|
});
|
|
expect(progressSpy).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should add a upload progress handler from instance config', function (done) {
|
|
const progressSpy = jasmine.createSpy('progress');
|
|
|
|
const instance = axios.create({
|
|
onUploadProgress: progressSpy,
|
|
});
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
// expect(progressSpy).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
|
|
it('should add upload and download progress handlers from instance config', function (done) {
|
|
const downloadProgressSpy = jasmine.createSpy('downloadProgress');
|
|
const uploadProgressSpy = jasmine.createSpy('uploadProgress');
|
|
|
|
const instance = axios.create({
|
|
onDownloadProgress: downloadProgressSpy,
|
|
onUploadProgress: uploadProgressSpy,
|
|
});
|
|
|
|
instance.get('/foo');
|
|
|
|
getAjaxRequest().then(function (request) {
|
|
// expect(uploadProgressSpy).toHaveBeenCalled();
|
|
expect(downloadProgressSpy).not.toHaveBeenCalled();
|
|
request.respondWith({
|
|
status: 200,
|
|
responseText: '{"foo": "bar"}',
|
|
});
|
|
expect(downloadProgressSpy).toHaveBeenCalled();
|
|
done();
|
|
});
|
|
});
|
|
});
|