Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
baiyaaaaa authored and Leopoldthecoder committed Feb 16, 2017
1 parent bd008ba commit 98850a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
13 changes: 8 additions & 5 deletions packages/upload/src/ajax.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
function getError(action, option, xhr) {
const msg = xhr.response
? (xhr.response.error || xhr.response)
: xhr.responseText
? xhr.responseText
: `fail to post ${action} ${xhr.status}'`;
let msg;
if (xhr.response) {
msg = `${xhr.status} ${xhr.response.error || xhr.response}`;
} else if (xhr.responseText) {
msg = `${xhr.status} ${xhr.responseText}`;
} else {
msg = `fail to post ${action} ${xhr.status}'`;
}

const err = new Error(msg);
err.status = xhr.status;
Expand Down
18 changes: 8 additions & 10 deletions test/unit/specs/upload.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ajax', () => {
});
it('40x code should be error', done => {
option.onError = e => {
expect(e.toString()).to.contain('404');
expect(e.toString()).to.contain('404 Not found');
done();
};

Expand Down Expand Up @@ -90,10 +90,10 @@ describe('Upload', () => {
handlers.onSuccess(res, file, fileList);
}
},
onError(err, response, file) {
console.log('onError', err, response);
onError(err, file, fileList) {
console.log('onError', err, file, fileList);
if (handlers.onError) {
handlers.onError(err, response, file);
handlers.onError(err, file, fileList);
}
},
onPreview(file) {
Expand Down Expand Up @@ -148,9 +148,9 @@ describe('Upload', () => {
type: 'xml'
}];

handlers.onError = (err, response, file) => {
handlers.onError = (err, file, fileList) => {
expect(err instanceof Error).to.equal(true);
expect(response).to.equal('error 400');
expect(file.name).to.equal('fail.png');
done();
};

Expand All @@ -173,7 +173,7 @@ describe('Upload', () => {

handlers.onSuccess = (res, file, fileList) => {
uploader.$nextTick(_ => {
uploader.$el.querySelector('.el-upload__files .is-finished a').click();
uploader.$el.querySelector('.el-upload-list .is-success a').click();
});
};

Expand All @@ -190,10 +190,9 @@ describe('Upload', () => {
}];

handlers.onSuccess = (res, file, fileList) => {
uploader.$el.querySelector('.el-upload__files .el-upload__btn-delete').click();
uploader.$el.querySelector('.el-upload-list .el-icon-close').click();
uploader.$nextTick(_ => {
expect(uploader.fileList.length).to.equal(0);
expect(uploader.$el.querySelector('.el-upload__files')).to.not.exist;
done();
});
};
Expand All @@ -214,7 +213,6 @@ describe('Upload', () => {
uploader.clearFiles();
uploader.$nextTick(_ => {
expect(uploader.fileList.length).to.equal(0);
expect(uploader.$el.querySelector('.el-upload__files')).to.not.exist;
done();
});
};
Expand Down

0 comments on commit 98850a1

Please sign in to comment.