diff --git a/src/ExpectedMessage.ts b/src/ExpectedMessage.ts index 294ca54..f5c783c 100644 --- a/src/ExpectedMessage.ts +++ b/src/ExpectedMessage.ts @@ -1,4 +1,4 @@ -import { IMessage, IEvent } from 'botbuilder'; +import { IEvent, IMessage } from 'botbuilder'; import { expect } from './assertionLibraries/IExpectation'; export enum ExpectedMessageType { @@ -90,7 +90,7 @@ export class ExpectedMessage { expectedResponseStrings.length > 1 ? `one of ${expectedResponseStrings}` : expectedResponseStrings[0]; const errorString = - `Bot should have responded with '${errorStringExpectedResponseText}', but was '${outgoingText}`; + `Bot should have responded with '${errorStringExpectedResponseText}', but was '${outgoingText}'`; expect(expectedResponseStrings, errorString).toInclude(outgoingText); } @@ -105,7 +105,7 @@ export class ExpectedMessage { const text = outgoingMessage.text; const regexCollection: RegExp[] = this.expectedResponseCollection as RegExp[]; expect(regexCollection.some((regex: RegExp) => regex.test(text)), - `${text} did not match any regex in ${regexCollection}`).toBeTrue(); + `'${text}' did not match any regex in ${regexCollection}`).toBeTrue(); } /** diff --git a/src/assertionLibraries/ChaiExpectation.ts b/src/assertionLibraries/ChaiExpectation.ts index 646a144..35d042a 100644 --- a/src/assertionLibraries/ChaiExpectation.ts +++ b/src/assertionLibraries/ChaiExpectation.ts @@ -30,33 +30,33 @@ const expectWithDeepMatch: DeepMatch = expect as any; export class ChaiExpectation implements IExpectation { private subject: {}; private message: string; - + constructor(subject: {}, message?: string) { this.subject = subject; this.message = message; } - + public notToBeEmpty(): void { expect(this.subject, this.message).not.to.be.empty; } - + public toEqual(value: {}): void { expect(this.subject, this.message).to.equal(value); } - + public toInclude(value: {}): void { expect(this.subject, this.message).to.include(value); } - + public toBeTrue(): void { expect(this.subject, this.message).to.be.true; } - + /** * deeply compares an outgoing message with the expected messages that are considered valid for this test to pass. * It does a subset comparison, so as long as the expected message is a subset of one of the expected responses, this will pass - * - * @param outgoingMessage actual message that bot sends + * + * @param outgoingMessage actual message that bot sends */ public toDeeplyInclude(outgoingMessage: IMessage): void { const expectedResponseCollectionAsIMessage: IMessage[] = this.subject as IMessage[]; diff --git a/src/assertionLibraries/IExpectation.ts b/src/assertionLibraries/IExpectation.ts index db8fc00..0f53090 100644 --- a/src/assertionLibraries/IExpectation.ts +++ b/src/assertionLibraries/IExpectation.ts @@ -26,8 +26,8 @@ function createExpectation(subject: {}, message?: string): IExpectation { switch (name) { case 'chai': - return new ChaiExpectation(subject); + return new ChaiExpectation(subject, message); default: - return new ChaiExpectation(subject); + return new ChaiExpectation(subject, message); } } diff --git a/test/BotTesterFailure.spec.ts b/test/BotTesterFailure.spec.ts index 0f3f10a..f36dfa6 100644 --- a/test/BotTesterFailure.spec.ts +++ b/test/BotTesterFailure.spec.ts @@ -26,7 +26,7 @@ describe('BotTester', () => { expect(new BotTester(bot) .sendMessageToBot('Hola!', 'NOPE') .runTest() - ).to.eventually.be.rejectedWith('expected [ \'NOPE\' ] to include \'hello!\'').notify(done); + ).to.eventually.be.rejectedWith('Bot should have responded with \'NOPE\', but was \'hello!\'').notify(done); }); it('will fail if one of multiple responses is incorrect', (done: Function) => { @@ -38,7 +38,19 @@ describe('BotTester', () => { expect(new BotTester(bot) .sendMessageToBot('Hola!', 'hello!', 'NOPE') .runTest() - ).to.eventually.be.rejectedWith('expected [ \'NOPE\' ] to include \'how are you doing?\'').notify(done); + ).to.eventually.be.rejectedWith('Bot should have responded with \'NOPE\', but was \'how are you doing?\'').notify(done); + }); + + it('it will fail if an empty collection is given', () => { + bot.dialog('/', (session: Session) => { + session.send('hello!'); + }); + + try { + new BotTester(bot).sendMessageToBot('Hola!', []); + } catch (error) { + expect(error.message).to.include('expected response collections cannot be empty'); + } }); it('Will fail if response is not in the random response collection', (done: Function) => { @@ -177,7 +189,7 @@ describe('BotTester', () => { expect(new BotTester(bot) .sendMessageToBot('abcd', numberRegex) .runTest() - ).to.be.rejected.notify(done); + ).to.eventually.be.rejectedWith('\'abcd\' did not match any regex in /^\\d+/').notify(done); }); it('can timeout', (done: Function) => {