diff --git a/README.md b/README.md index b89b188d1..257adfc02 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ The `Pact` interface provides the following high-level APIs, they are listed in |`addInteraction()` |`Object` |`Promise`|Register an expectation on the Mock Server, which must be called by your test case(s). You can add multiple interactions per server. These will be validated and written to a pact if successful. |`verify()` |n/a |`Promise`|Verifies that all interactions specified | |`finalize()` |n/a |`Promise`|Records the interactions registered to the Mock Server into the pact file and shuts it down. | +|`removeInteractions` |n/a |`Promise`|In some cases you might want to clear out the expectations of the Mock Service, call this to clear out any expectations for the next test run. _NOTE_: `verify()` will implicitly call this. | #### Example The first step is to create a test for your API Consumer. The example below uses [Mocha](https://mochajs.org), and demonstrates the basic approach: diff --git a/karma/jasmine/client-spec.js b/karma/jasmine/client-spec.js index 57dfbfa29..ded57e65d 100644 --- a/karma/jasmine/client-spec.js +++ b/karma/jasmine/client-spec.js @@ -3,19 +3,19 @@ describe("Client", function() { - var client, provider; + var client, provider beforeAll(function(done) { client = example.createClient('http://localhost:1234') provider = Pact({ consumer: 'Karma Jasmine', provider: 'Hello' }) // required for slower Travis CI environment setTimeout(function () { done() }, 2000) - }); + }) afterAll(function (done) { provider.finalize() .then(function () { done() }, function (err) { done.fail(err) }) - }); + }) describe("sayHello", function () { beforeAll(function (done) { @@ -38,17 +38,17 @@ //Run the tests client.sayHello() .then(function (data) { - expect(JSON.parse(data.responseText)).toEqual({ reply: "Hello" }); + expect(JSON.parse(data.responseText)).toEqual({ reply: "Hello" }) done() }) .catch(function (err) { done.fail(err) }) - }); + }) // verify with Pact, and reset expectations - it('successfully verifies', function() { provider.verify() }); - }); + it('successfully verifies', function() { provider.verify() }) + }) describe("findFriendsByAgeAndChildren", function () { @@ -82,17 +82,17 @@ //Run the tests client.findFriendsByAgeAndChildren('33', ['Mary Jane', 'James']) .then(function (res) { - expect(JSON.parse(res.responseText)).toEqual({friends: [{ name: 'Sue' }]}); + expect(JSON.parse(res.responseText)).toEqual({friends: [{ name: 'Sue' }]}) done() }) .catch(function (err) { done.fail(err) }) - }); + }) // verify with Pact, and reset expectations - it('successfully verifies', function() { provider.verify() }); - }); + it('successfully verifies', function() { provider.verify() }) + }) describe("unfriendMe", function () { @@ -126,10 +126,10 @@ .catch(function (err) { done.fail(err) }) - }); + }) - it('successfully verifies', function() { provider.verify() }); - }); + it('successfully verifies', function() { provider.verify() }) + }) // verify with Pact, and reset expectations describe("when there are no friends", function () { @@ -155,14 +155,14 @@ done(new Error('expected request to /unfriend me to fail')) }, function(e) { done() - }); + }) - }); + }) // verify with Pact, and reset expectations - it('successfully verifies', function() { provider.verify() }); - }); - }); + it('successfully verifies', function() { provider.verify() }) + }) + }) - }); -})(); + }) +})() diff --git a/karma/mocha/client-spec.js b/karma/mocha/client-spec.js index 1d0ec1d09..5262434d4 100644 --- a/karma/mocha/client-spec.js +++ b/karma/mocha/client-spec.js @@ -3,10 +3,10 @@ describe("Client", function() { - var client, provider; + var client, provider before(function(done) { - client = example.createClient('http://localhost:1234'); + client = example.createClient('http://localhost:1234') provider = Pact({ consumer: 'Karma Mocha', provider: 'Hello' }) // required for slower Travis CI environment setTimeout(function () { done() }, 1000) @@ -38,17 +38,17 @@ //Run the tests client.sayHello() .then(function (data) { - expect(JSON.parse(data.responseText)).to.eql({ reply: "Hello" }); + expect(JSON.parse(data.responseText)).to.eql({ reply: "Hello" }) done() }) .catch(function (err) { done(err) }) - }); + }) // verify with Pact, and reset expectations - it('successfully verifies', function() { provider.verify() }); - }); + it('successfully verifies', function() { provider.verify() }) + }) describe("findFriendsByAgeAndChildren", function () { @@ -82,17 +82,17 @@ //Run the tests client.findFriendsByAgeAndChildren('33', ['Mary Jane', 'James']) .then(function (res) { - expect(JSON.parse(res.responseText)).to.eql({friends: [{ name: 'Sue' }]}); + expect(JSON.parse(res.responseText)).to.eql({friends: [{ name: 'Sue' }]}) done() }) .catch(function (err) { done(err) }) - }); + }) // verify with Pact, and reset expectations - it('successfully verifies', function() { provider.verify() }); - }); + it('successfully verifies', function() { provider.verify() }) + }) describe("unfriendMe", function () { @@ -126,10 +126,10 @@ .catch(function (err) { done(err) }) - }); + }) - it('successfully verifies', function() { provider.verify() }); - }); + it('successfully verifies', function() { provider.verify() }) + }) // verify with Pact, and reset expectations describe("when there are no friends", function () { @@ -155,14 +155,14 @@ done(new Error('expected request to /unfriend me to fail')) }, function(e) { done() - }); + }) - }); + }) // verify with Pact, and reset expectations - it('successfully verifies', function() { provider.verify() }); - }); - }); + it('successfully verifies', function() { provider.verify() }) + }) + }) - }); -})(); + }) +})()