Skip to content

Commit c45e1eb

Browse files
committed
test case fix
1 parent 5042653 commit c45e1eb

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import errorMessages from "./constants/errorMessages";
33
import { ImageKitOptions, UploadOptions, UploadResponse, UrlOptions } from "./interfaces";
44
import IKResponse from "./interfaces/IKResponse";
55
import { upload } from "./upload/index";
6+
import respond from "./utils/respond";
67
import { url } from "./url/index";
78
import transformationUtils from "./utils/transformation";
89

@@ -80,14 +81,14 @@ class ImageKit {
8081
upload(uploadOptions: UploadOptions, callback: (err: Error | null, response: IKResponse<UploadResponse> | null) => void, options?: Partial<ImageKitOptions>): void;
8182
upload(uploadOptions: UploadOptions, callbackOrOptions?: ((err: Error | null, response: IKResponse<UploadResponse> | null) => void) | Partial<ImageKitOptions>, options?: Partial<ImageKitOptions>): void | Promise<IKResponse<UploadResponse>> {
8283
let callback;
83-
if (typeof uploadOptions !== "object") {
84-
throw ("First parameter needs to be object");
85-
}
8684
if (typeof callbackOrOptions === 'function') {
8785
callback = callbackOrOptions;
8886
} else {
8987
options = callbackOrOptions || {};
9088
}
89+
if (!uploadOptions || typeof uploadOptions !== "object") {
90+
return respond(true, errorMessages.INVALID_UPLOAD_OPTIONS, callback);
91+
}
9192
var mergedOptions = {
9293
...this.options,
9394
...options,

test/upload.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,14 @@ describe("File upload", function () {
102102
server.restore();
103103
});
104104

105-
it('Invalid options', function (done) {
105+
it('Invalid options', function () {
106106
var callback = sinon.spy();
107107

108-
try {
109-
imagekit.upload(undefined, callback);
110-
} catch (ex) {
111-
// console.log(ex);
112-
expect(ex).to.be.deep.equal("First parameter needs to be object");
113-
done();
114-
}
108+
imagekit.upload(undefined, callback);
109+
expect(server.requests.length).to.be.equal(0);
110+
// await sleep()
111+
expect(callback.calledOnce).to.be.true;
112+
sinon.assert.calledWith(callback, { help: "", message: "Invalid uploadOptions parameter" }, null);
115113
});
116114

117115
it('Missing fileName', function () {

0 commit comments

Comments
 (0)