Skip to content

Commit

Permalink
fix(test): update jest tests with new API, fixes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 19, 2017
1 parent a06a14d commit 4eb2e1c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 28 deletions.
36 changes: 11 additions & 25 deletions examples/jest/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
'use strict'

const path = require('path')
const Pact = require('pact')
const wrapper = require('@pact-foundation/pact-node')
const Pact = require('../../../src/pact.js');
const getMeDogs = require('../index').getMeDogs

describe("Dog's API", () => {
let url = 'http://localhost'
let provider

const port = 8989;
const server = wrapper.createServer({
const provider = Pact({
port: port,
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
Expand All @@ -21,23 +19,12 @@ describe("Dog's API", () => {

const EXPECTED_BODY = [{dog: 1}]

afterAll(() => {
wrapper.removeAllServers();
})

afterEach(done => {
server.delete().then(done)
});
beforeAll(() => provider.setup())

beforeEach(done => {
server.start().then(() => {
provider = Pact({ consumer: 'MyConsumer', provider: 'MyProvider', port: port })
done()
})
});
afterAll(() => provider.finalize())

describe("works", () => {
beforeEach(done => {
beforeAll(done => {
const interaction = {
state: 'i have a list of projects',
uponReceiving: 'a request for projects',
Expand All @@ -55,19 +42,18 @@ describe("Dog's API", () => {
provider.addInteraction(interaction).then(done, done)
})

afterEach(done => {
return provider.finalize().then(done, done)
})

it('successfully verifies', done => {
// add expectations
it('returns a sucessful body', done => {
return getMeDogs({ url, port })
.then(provider.verify)
.then(response => {
expect(response.headers['content-type']).toEqual('application/json');
expect(response.data).toEqual(EXPECTED_BODY);
expect(response.status).toEqual(200);
done();
})
.then(done, done)
})

// verify with Pact, and reset expectations
it('successfully verifies', () => provider.verify())
})
})
4 changes: 1 addition & 3 deletions examples/jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"testEnvironment": "node"
},
"devDependencies": {
"@pact-foundation/pact-node": "^4.5.3",
"axios": "^0.14.0",
"jest-cli": "^15.1.1",
"pact": "^1.0.0-rc.5"
"jest-cli": "^15.1.1"
}
}

0 comments on commit 4eb2e1c

Please sign in to comment.