Skip to content

Commit

Permalink
feat(karma): update code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 19, 2017
1 parent 7182c7b commit ef27b7c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
42 changes: 21 additions & 21 deletions karma/jasmine/client-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 () {

Expand Down Expand Up @@ -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 () {

Expand Down Expand Up @@ -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 () {
Expand All @@ -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() })
})
})

});
})();
})
})()
40 changes: 20 additions & 20 deletions karma/mocha/client-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 () {

Expand Down Expand Up @@ -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 () {

Expand Down Expand Up @@ -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 () {
Expand All @@ -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() })
})
})

});
})();
})
})()

0 comments on commit ef27b7c

Please sign in to comment.