|
1 | 1 | /*eslint-disable*/ |
2 | | -(function() { |
| 2 | +(function () { |
3 | 3 |
|
4 | | - describe("Client", function() { |
| 4 | + describe("Client", function () { |
5 | 5 |
|
6 | 6 | var client, provider |
7 | 7 |
|
8 | | - beforeAll(function(done) { |
| 8 | + beforeAll(function (done) { |
9 | 9 | client = example.createClient('http://localhost:1234') |
10 | | - provider = Pact({ consumer: 'Karma Jasmine', provider: 'Hello' }) |
| 10 | + provider = new Pact.PactWeb({ consumer: 'Karma Jasmine', provider: 'Hello' }) |
11 | 11 |
|
12 | 12 | // required for slower Travis CI environment |
13 | 13 | setTimeout(function () { done() }, 2000) |
|
35 | 35 | body: { reply: "Hello" } |
36 | 36 | } |
37 | 37 | }) |
38 | | - .then(function () { done() }, function (err) { done.fail(err) }) |
| 38 | + .then(function () { done() }, function (err) { done.fail(err) }) |
39 | 39 | }) |
40 | 40 |
|
41 | | - it("should say hello", function(done) { |
| 41 | + it("should say hello", function (done) { |
42 | 42 | //Run the tests |
43 | 43 | client.sayHello() |
44 | 44 | .then(function (data) { |
|
51 | 51 | }) |
52 | 52 |
|
53 | 53 | // verify with Pact, and reset expectations |
54 | | - it('successfully verifies', function(done) { |
| 54 | + it('successfully verifies', function (done) { |
55 | 55 | provider.verify() |
56 | | - .then(function(a) { |
| 56 | + .then(function (a) { |
57 | 57 | done() |
58 | | - }, function(e) { |
| 58 | + }, function (e) { |
59 | 59 | done.fail(e) |
60 | 60 | }) |
61 | 61 | }) |
|
64 | 64 | describe("findFriendsByAgeAndChildren", function () { |
65 | 65 |
|
66 | 66 | beforeAll(function (done) { |
67 | | - provider |
| 67 | + provider |
68 | 68 | .addInteraction({ |
69 | 69 | uponReceiving: 'a request friends', |
70 | 70 | withRequest: { |
71 | 71 | method: 'GET', |
72 | 72 | path: '/friends', |
73 | 73 | query: { |
74 | | - age: Pact.Matchers.term({generate: '30', matcher: '\\d+'}), //remember query params are always strings |
| 74 | + age: Pact.Matchers.term({ generate: '30', matcher: '\\d+' }), //remember query params are always strings |
75 | 75 | children: ['Mary Jane', 'James'] // specify params with multiple values in an array |
76 | 76 | }, |
77 | 77 | headers: { 'Accept': 'application/json' } |
|
89 | 89 | .then(function () { done() }, function (err) { done.fail(err) }) |
90 | 90 | }) |
91 | 91 |
|
92 | | - it("should return some friends", function(done) { |
| 92 | + it("should return some friends", function (done) { |
93 | 93 | //Run the tests |
94 | 94 | client.findFriendsByAgeAndChildren('33', ['Mary Jane', 'James']) |
95 | 95 | .then(function (res) { |
96 | | - expect(JSON.parse(res.responseText)).toEqual({friends: [{ name: 'Sue' }]}) |
| 96 | + expect(JSON.parse(res.responseText)).toEqual({ friends: [{ name: 'Sue' }] }) |
97 | 97 | done() |
98 | 98 | }) |
99 | 99 | .catch(function (err) { |
|
103 | 103 |
|
104 | 104 | // verify with Pact, and reset expectations |
105 | 105 | // verify with Pact, and reset expectations |
106 | | - it('successfully verifies', function(done) { |
| 106 | + it('successfully verifies', function (done) { |
107 | 107 | provider.verify() |
108 | | - .then(function(a) { |
| 108 | + .then(function (a) { |
109 | 109 | done() |
110 | | - }, function(e) { |
| 110 | + }, function (e) { |
111 | 111 | done.fail(e) |
112 | 112 | }) |
113 | 113 | }) |
|
136 | 136 | body: { reply: "Bye" } |
137 | 137 | } |
138 | 138 | }) |
139 | | - .then(function () { done() }, function (err) { done.fail(err) }) |
| 139 | + .then(function () { done() }, function (err) { done.fail(err) }) |
140 | 140 | }) |
141 | 141 |
|
142 | | - it("should unfriend me", function(done) { |
| 142 | + it("should unfriend me", function (done) { |
143 | 143 | //Run the tests |
144 | 144 | client.unfriendMe() |
145 | 145 | .then(function (res) { |
|
152 | 152 | }) |
153 | 153 |
|
154 | 154 | // verify with Pact, and reset expectations |
155 | | - it('successfully verifies', function(done) { |
| 155 | + it('successfully verifies', function (done) { |
156 | 156 | provider.verify() |
157 | | - .then(function(a) { |
| 157 | + .then(function (a) { |
158 | 158 | done() |
159 | | - }, function(e) { |
| 159 | + }, function (e) { |
160 | 160 | done.fail(e) |
161 | 161 | }) |
162 | 162 | }) |
|
178 | 178 | body: { error: "No friends :(" } |
179 | 179 | } |
180 | 180 | }) |
181 | | - .then(function () { done() }, function (err) { done.fail(err) }) |
| 181 | + .then(function () { done() }, function (err) { done.fail(err) }) |
182 | 182 | }) |
183 | 183 |
|
184 | 184 | it("returns an error message", function (done) { |
185 | 185 | //Run the tests |
186 | | - client.unfriendMe().then(function() { |
| 186 | + client.unfriendMe().then(function () { |
187 | 187 | done(new Error('expected request to /unfriend me to fail')) |
188 | | - }, function(e) { |
| 188 | + }, function (e) { |
189 | 189 | expect(e.status).toEqual(404) |
190 | 190 | expect(JSON.parse(e.responseText).error).toEqual('No friends :(') |
191 | 191 | done() |
|
195 | 195 |
|
196 | 196 | // verify with Pact, and reset expectations |
197 | 197 | // verify with Pact, and reset expectations |
198 | | - it('successfully verifies', function(done) { |
| 198 | + it('successfully verifies', function (done) { |
199 | 199 | provider.verify() |
200 | | - .then(function(a) { |
| 200 | + .then(function (a) { |
201 | 201 | done() |
202 | | - }, function(e) { |
| 202 | + }, function (e) { |
203 | 203 | done.fail(e) |
204 | 204 | }) |
205 | 205 | }) |
|
0 commit comments