Skip to content

Commit 93cba30

Browse files
committed
fix(examples): update jasmine karma example with best practice #122
1 parent 786d3d0 commit 93cba30

File tree

1 file changed

+12
-86
lines changed

1 file changed

+12
-86
lines changed

karma/jasmine/client-spec.js

Lines changed: 12 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@
2020
})
2121

2222
afterAll(function (done) {
23-
provider.finalize()
24-
.then(function () {
25-
done()
26-
}, function (err) {
27-
done.fail(err)
28-
})
23+
provider.finalize().then(done, done.fail)
2924
})
3025

3126
describe("sayHello", function () {
@@ -46,11 +41,7 @@
4641
}
4742
}
4843
})
49-
.then(function () {
50-
done()
51-
}, function (err) {
52-
done.fail(err)
53-
})
44+
.then(done, done.fail)
5445
})
5546

5647
it("should say hello", function (done) {
@@ -60,21 +51,8 @@
6051
expect(JSON.parse(data.responseText)).toEqual({
6152
reply: "Hello"
6253
})
63-
done()
64-
})
65-
.catch(function (err) {
66-
done.fail(err)
67-
})
68-
})
69-
70-
// verify with Pact, and reset expectations
71-
it('successfully verifies', function (done) {
72-
provider.verify()
73-
.then(function (a) {
74-
done()
75-
}, function (e) {
76-
done.fail(e)
77-
})
54+
provider.verify().then(done, done.fail)
55+
}, done.fail)
7856
})
7957
})
8058

@@ -112,11 +90,7 @@
11290
}
11391
}
11492
})
115-
.then(function () {
116-
done()
117-
}, function (err) {
118-
done.fail(err)
119-
})
93+
.then(done, done.fail)
12094
})
12195

12296
it("should return some friends", function (done) {
@@ -128,22 +102,8 @@
128102
name: 'Sue'
129103
}]
130104
})
131-
done()
132-
})
133-
.catch(function (err) {
134-
done.fail(err)
135-
})
136-
})
137-
138-
// verify with Pact, and reset expectations
139-
// verify with Pact, and reset expectations
140-
it('successfully verifies', function (done) {
141-
provider.verify()
142-
.then(function (a) {
143-
done()
144-
}, function (e) {
145-
done.fail(e)
146-
})
105+
provider.verify().then(done, done.fail)
106+
}, done.fail)
147107
})
148108
})
149109

@@ -174,11 +134,7 @@
174134
}
175135
}
176136
})
177-
.then(function () {
178-
done()
179-
}, function (err) {
180-
done.fail(err)
181-
})
137+
.then(done, done.fail)
182138
})
183139

184140
it("should unfriend me", function (done) {
@@ -188,21 +144,8 @@
188144
expect(JSON.parse(res.responseText)).toEqual({
189145
reply: "Bye"
190146
})
191-
done()
192-
})
193-
.catch(function (err) {
194-
done.fail(err)
195-
})
196-
})
197-
198-
// verify with Pact, and reset expectations
199-
it('successfully verifies', function (done) {
200-
provider.verify()
201-
.then(function (a) {
202-
done()
203-
}, function (e) {
204-
done.fail(e)
205-
})
147+
provider.verify().then(done, done.fail)
148+
}, done.fail)
206149
})
207150
})
208151

@@ -224,11 +167,7 @@
224167
}
225168
}
226169
})
227-
.then(function () {
228-
done()
229-
}, function (err) {
230-
done.fail(err)
231-
})
170+
.then(done, done.fail)
232171
})
233172

234173
it("returns an error message", function (done) {
@@ -238,23 +177,10 @@
238177
}, function (e) {
239178
expect(e.status).toEqual(404)
240179
expect(JSON.parse(e.responseText).error).toEqual('No friends :(')
241-
done()
180+
provider.verify().then(done, done.fail)
242181
})
243-
244-
})
245-
246-
// verify with Pact, and reset expectations
247-
// verify with Pact, and reset expectations
248-
it('successfully verifies', function (done) {
249-
provider.verify()
250-
.then(function (a) {
251-
done()
252-
}, function (e) {
253-
done.fail(e)
254-
})
255182
})
256183
})
257184
})
258-
259185
})
260186
})()

0 commit comments

Comments
 (0)