diff --git a/packages/mail/src/mail.d.ts b/packages/mail/src/mail.d.ts index fa827498..0930ddc0 100644 --- a/packages/mail/src/mail.d.ts +++ b/packages/mail/src/mail.d.ts @@ -32,12 +32,12 @@ declare class MailService { /** * Send email */ - send(data: MailDataRequired | MailDataRequired[], isMultiple?: boolean, cb?: (err: Error | ResponseError, result: [ClientResponse, {}]) => void): Promise<[ClientResponse, {}]>; + send(data: MailDataRequired | MailDataRequired[], isMultiple?: boolean, cb?: (err: Error | ResponseError | null, result: [ClientResponse, {}]) => void): Promise<[ClientResponse, {}]>; /** * Send multiple emails (shortcut) */ - sendMultiple(data: MailDataRequired, cb?: (error: Error | ResponseError, result: [ClientResponse, {}]) => void): Promise<[ClientResponse, {}]>; + sendMultiple(data: MailDataRequired, cb?: (error: Error | ResponseError | null, result: [ClientResponse, {}]) => void): Promise<[ClientResponse, {}]>; } declare const mail: MailService; diff --git a/packages/mail/src/mail.spec.js b/packages/mail/src/mail.spec.js index 09698baa..623161b6 100644 --- a/packages/mail/src/mail.spec.js +++ b/packages/mail/src/mail.spec.js @@ -47,6 +47,21 @@ describe('sgMail.send()', () => { }); }); + it('should not be null(error) in callBack function for unsuccessfully delivered emails', (done) => { + sgMail.send({}, false, (error, response) => { + expect(error).to.not.be.null(); + done(); + }); + }); + + it('should be null(error) in callBack function for successfully delivered emails', (done) => { + sgClient.setDefaultHeader('X-Mock', 202); + sgMail.send(data, false, (error, response) => { + expect(error).to.be.null(); + done(); + }); + }); + it('should throw an error if callback is not a function', () => { return expect(function() { sgMail.send(data, false, {});