Skip to content

Commit

Permalink
fix(interaction-failure): clear interactions on any verify()
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mefellows committed Oct 17, 2018
1 parent ac27a1e commit fbc5ac0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
]);
});
});
Expand Down
7 changes: 5 additions & 2 deletions src/pact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,18 @@ export class Pact {
return this.mockService.verify()
.then(() => this.mockService.removeInteractions())
.catch((e: any) => {

// Properly format the error
/* tslint:disable: no-console */
console.error("");
console.error(clc.red("Pact verification failed!"));
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.");
})
})
}

/**
Expand Down

0 comments on commit fbc5ac0

Please sign in to comment.