From fbc5ac0f9f6d53bccac4c43393295bbaed7f28c6 Mon Sep 17 00:00:00 2001 From: Matt Fellows Date: Thu, 18 Oct 2018 10:27:28 +1100 Subject: [PATCH] fix(interaction-failure): clear interactions on any verify() All successful/failed calls to pact.verify() should clear interactions so that subsequent tests don't det out of whack. NOTE: Promise.finally() would have been nicer, note for upgrade to latest TS in next major release. Fixes #231 --- src/pact.spec.ts | 2 +- src/pact.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pact.spec.ts b/src/pact.spec.ts index b7849728a..4fe731dbf 100644 --- a/src/pact.spec.ts +++ b/src/pact.spec.ts @@ -245,7 +245,7 @@ describe("Pact", () => { const verifyPromise = b.verify(); return Promise.all([ expect(verifyPromise).to.eventually.be.rejectedWith(Error), - verifyPromise.catch(() => expect(removeInteractionsStub).to.callCount(0)), + verifyPromise.catch(() => expect(removeInteractionsStub).to.callCount(1)), ]); }); }); diff --git a/src/pact.ts b/src/pact.ts index ca22a7ff4..61afc6ba4 100644 --- a/src/pact.ts +++ b/src/pact.ts @@ -127,6 +127,7 @@ export class Pact { return this.mockService.verify() .then(() => this.mockService.removeInteractions()) .catch((e: any) => { + // Properly format the error /* tslint:disable: no-console */ console.error(""); @@ -134,8 +135,10 @@ export class Pact { console.error(clc.red(e)); /* tslint:enable: */ - throw new Error("Pact verification failed - expected interactions did not match actual."); - }); + return this.mockService.removeInteractions().then(() => { + throw new Error("Pact verification failed - expected interactions did not match actual."); + }) + }) } /**