|
38 | 38 | })
|
39 | 39 | })
|
40 | 40 |
|
41 |
| - it("should say hello", function (done) { |
| 41 | + it("should say hello", function () { |
42 | 42 | //Run the tests
|
43 |
| - client.sayHello() |
| 43 | + return client.sayHello() |
44 | 44 | .then(function (data) {
|
45 | 45 | expect(JSON.parse(data.responseText)).to.eql({
|
46 | 46 | reply: "Hello"
|
47 | 47 | })
|
48 |
| - done() |
49 |
| - }) |
50 |
| - .catch(function (err) { |
51 |
| - done(err) |
| 48 | + // verify with Pact, and reset expectations |
| 49 | + return provider.verify() |
52 | 50 | })
|
53 | 51 | })
|
54 |
| - |
55 |
| - // verify with Pact, and reset expectations |
56 |
| - it('successfully verifies', function () { |
57 |
| - return provider.verify() |
58 |
| - }) |
59 | 52 | })
|
60 | 53 |
|
61 | 54 | describe("findFriendsByAgeAndChildren", function () {
|
62 |
| - |
63 |
| - before(function (done) { |
64 |
| - provider |
| 55 | + before(function () { |
| 56 | + return provider |
65 | 57 | .addInteraction({
|
66 | 58 | uponReceiving: 'a request friends',
|
67 | 59 | withRequest: {
|
|
92 | 84 | }
|
93 | 85 | }
|
94 | 86 | })
|
95 |
| - .then(function () { |
96 |
| - done() |
97 |
| - }, function (err) { |
98 |
| - done(err) |
99 |
| - }) |
100 | 87 | })
|
101 | 88 |
|
102 |
| - it("should return some friends", function (done) { |
| 89 | + it("should return some friends", function () { |
103 | 90 | //Run the tests
|
104 |
| - client.findFriendsByAgeAndChildren('33', ['Mary Jane', 'James']) |
| 91 | + return client.findFriendsByAgeAndChildren('33', ['Mary Jane', 'James']) |
105 | 92 | .then(function (res) {
|
106 | 93 | expect(JSON.parse(res.responseText)).to.eql({
|
107 | 94 | friends: [{
|
108 | 95 | name: 'Sue'
|
109 | 96 | }]
|
110 | 97 | })
|
111 |
| - done() |
112 |
| - }) |
113 |
| - .catch(function (err) { |
114 |
| - done(err) |
| 98 | + // verify with Pact, and reset expectations |
| 99 | + return provider.verify() |
115 | 100 | })
|
116 | 101 | })
|
117 |
| - |
118 |
| - // verify with Pact, and reset expectations |
119 |
| - it('successfully verifies', function () { |
120 |
| - return provider.verify() |
121 |
| - }) |
122 | 102 | })
|
123 | 103 |
|
124 | 104 | describe("unfriendMe", function () {
|
|
128 | 108 | })
|
129 | 109 |
|
130 | 110 | describe("when I have some friends", function () {
|
131 |
| - |
132 |
| - before(function (done) { |
| 111 | + before(function () { |
133 | 112 | //Add interaction
|
134 |
| - provider.addInteraction({ |
135 |
| - state: 'I am friends with Fred', |
136 |
| - uponReceiving: 'a request to unfriend', |
137 |
| - withRequest: { |
138 |
| - method: 'PUT', |
139 |
| - path: '/unfriendMe' |
| 113 | + return provider.addInteraction({ |
| 114 | + state: 'I am friends with Fred', |
| 115 | + uponReceiving: 'a request to unfriend', |
| 116 | + withRequest: { |
| 117 | + method: 'PUT', |
| 118 | + path: '/unfriendMe' |
| 119 | + }, |
| 120 | + willRespondWith: { |
| 121 | + status: 200, |
| 122 | + headers: { |
| 123 | + "Content-Type": "application/json" |
140 | 124 | },
|
141 |
| - willRespondWith: { |
142 |
| - status: 200, |
143 |
| - headers: { |
144 |
| - "Content-Type": "application/json" |
145 |
| - }, |
146 |
| - body: { |
147 |
| - reply: "Bye" |
148 |
| - } |
| 125 | + body: { |
| 126 | + reply: "Bye" |
149 | 127 | }
|
150 |
| - }) |
151 |
| - .then(function () { |
152 |
| - done() |
153 |
| - }, function (err) { |
154 |
| - done(err) |
155 |
| - }) |
| 128 | + } |
| 129 | + }) |
156 | 130 | })
|
157 | 131 |
|
158 |
| - it("should unfriend me", function (done) { |
| 132 | + it("should unfriend me", function () { |
159 | 133 | //Run the tests
|
160 |
| - client.unfriendMe() |
| 134 | + return client.unfriendMe() |
161 | 135 | .then(function (res) {
|
162 | 136 | expect(JSON.parse(res.responseText)).to.eql({
|
163 | 137 | reply: "Bye"
|
164 | 138 | })
|
165 |
| - done() |
166 |
| - }) |
167 |
| - .catch(function (err) { |
168 |
| - done(err) |
| 139 | + // verify with Pact, and reset expectations |
| 140 | + return provider.verify() |
169 | 141 | })
|
170 | 142 | })
|
171 |
| - |
172 |
| - it('successfully verifies', function () { |
173 |
| - return provider.verify() |
174 |
| - }) |
175 | 143 | })
|
176 | 144 |
|
177 | 145 | // verify with Pact, and reset expectations
|
178 | 146 | describe("when there are no friends", function () {
|
179 |
| - before(function (done) { |
| 147 | + before(function () { |
180 | 148 | //Add interaction
|
181 |
| - provider.addInteraction({ |
182 |
| - state: 'I have no friends', |
183 |
| - uponReceiving: 'a request to unfriend', |
184 |
| - withRequest: { |
185 |
| - method: 'PUT', |
186 |
| - path: '/unfriendMe' |
187 |
| - }, |
188 |
| - willRespondWith: { |
189 |
| - status: 404, |
190 |
| - body: {} |
191 |
| - } |
192 |
| - }) |
193 |
| - .then(function () { |
194 |
| - done() |
195 |
| - }, function (err) { |
196 |
| - done(err) |
197 |
| - }) |
| 149 | + return provider.addInteraction({ |
| 150 | + state: 'I have no friends', |
| 151 | + uponReceiving: 'a request to unfriend', |
| 152 | + withRequest: { |
| 153 | + method: 'PUT', |
| 154 | + path: '/unfriendMe' |
| 155 | + }, |
| 156 | + willRespondWith: { |
| 157 | + status: 404, |
| 158 | + body: {} |
| 159 | + } |
| 160 | + }) |
198 | 161 | })
|
199 | 162 |
|
200 |
| - it("returns an error message", function (done) { |
| 163 | + it("returns an error message", function () { |
201 | 164 | //Run the tests
|
202 |
| - client.unfriendMe().then(function () { |
203 |
| - done(new Error('expected request to /unfriend me to fail')) |
| 165 | + return client.unfriendMe().then(function () { |
| 166 | + throw new Error('expected request to /unfriend me to fail') |
204 | 167 | }, function (e) {
|
205 | 168 | expect(e).to.eql('No friends :(')
|
206 |
| - done() |
| 169 | + // verify with Pact, and reset expectations |
| 170 | + return provider.verify() |
207 | 171 | })
|
208 |
| - |
209 |
| - }) |
210 |
| - |
211 |
| - // verify with Pact, and reset expectations |
212 |
| - it('successfully verifies', function () { |
213 |
| - return provider.verify() |
214 | 172 | })
|
215 | 173 | })
|
216 | 174 | })
|
217 |
| - |
218 | 175 | })
|
219 | 176 | })()
|
0 commit comments