hamjest 3.7.3 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/.eslintrc +15 -11
  2. package/dist/hamjest.js +6542 -23401
  3. package/dist/hamjest.min.js +1 -1
  4. package/gulpfile.js +0 -2
  5. package/index.js +95 -1
  6. package/lib/Description.js +32 -22
  7. package/lib/assertThat.js +4 -4
  8. package/lib/matchers/AllOf.js +8 -5
  9. package/lib/matchers/AnyOf.js +8 -8
  10. package/lib/matchers/DateComparisonMatcher.js +25 -24
  11. package/lib/matchers/Every.js +17 -11
  12. package/lib/matchers/FeatureMatcher.js +2 -2
  13. package/lib/matchers/Is.js +6 -5
  14. package/lib/matchers/IsAnything.js +2 -2
  15. package/lib/matchers/IsArray.js +4 -3
  16. package/lib/matchers/IsArrayContaining.js +8 -6
  17. package/lib/matchers/IsArrayContainingInAnyOrder.js +11 -8
  18. package/lib/matchers/IsArrayOrderedBy.js +5 -4
  19. package/lib/matchers/IsArrayWithItem.js +11 -8
  20. package/lib/matchers/IsArrayWithItems.js +6 -4
  21. package/lib/matchers/IsBoolean.js +4 -3
  22. package/lib/matchers/IsCloseTo.js +2 -2
  23. package/lib/matchers/IsDate.js +4 -3
  24. package/lib/matchers/IsDefined.js +4 -3
  25. package/lib/matchers/IsEqual.js +4 -3
  26. package/lib/matchers/IsFulfilled.js +2 -2
  27. package/lib/matchers/IsFunction.js +4 -3
  28. package/lib/matchers/IsFunctionThrowing.js +2 -2
  29. package/lib/matchers/IsInstanceOf.js +4 -3
  30. package/lib/matchers/IsNot.js +6 -5
  31. package/lib/matchers/IsNumber.js +4 -3
  32. package/lib/matchers/IsObject.js +4 -3
  33. package/lib/matchers/IsObjectWithProperties.js +19 -12
  34. package/lib/matchers/IsPromise.js +4 -3
  35. package/lib/matchers/IsRegExp.js +5 -6
  36. package/lib/matchers/IsRejected.js +2 -2
  37. package/lib/matchers/IsSame.js +2 -2
  38. package/lib/matchers/IsString.js +4 -3
  39. package/lib/matchers/IsStringMatching.js +2 -2
  40. package/lib/matchers/Matcher.js +10 -7
  41. package/lib/matchers/NumberComparisonMatcher.js +17 -16
  42. package/lib/matchers/SubstringMatcher.js +42 -39
  43. package/lib/matchers/failsToMatch.js +2 -2
  44. package/lib/matchers/falsy.js +2 -2
  45. package/lib/matchers/hasDescription.js +6 -5
  46. package/lib/matchers/hasExactlyOneItem.js +11 -8
  47. package/lib/matchers/hasSize.js +7 -4
  48. package/lib/matchers/inRange.js +11 -8
  49. package/lib/matchers/isEmpty.js +2 -2
  50. package/lib/matchers/matches.js +2 -2
  51. package/lib/matchers/promiseAgnostic.js +35 -15
  52. package/lib/matchers/returns.js +2 -2
  53. package/lib/matchers/truthy.js +2 -2
  54. package/lib/promiseThat.js +7 -9
  55. package/package.json +4 -5
  56. package/test/node/assertThatSpec.js +1 -3
  57. package/test/node/deferMatcher.js +2 -4
  58. package/test/node/esm/.eslintrc +5 -0
  59. package/test/node/esm/package.json +3 -0
  60. package/test/node/esm/providesNamedImports.js +3 -0
  61. package/test/node/matchers/AllOfSpec.js +1 -1
  62. package/test/node/matchers/AnyOfSpec.js +1 -1
  63. package/test/node/matchers/IsFulfilledSpec.js +29 -30
  64. package/test/node/matchers/IsPromiseSpec.js +3 -4
  65. package/test/node/matchers/IsRejectedSpec.js +21 -22
  66. package/test/node/promiseThatSpec.js +49 -86
  67. package/lib/hamjest.js +0 -106
  68. package/tags +0 -2855
@@ -2,7 +2,6 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const assert = require('assert');
5
- const Bluebird = require('bluebird');
6
5
 
7
6
  const __ = require('../../..');
8
7
 
@@ -20,7 +19,7 @@ describe('IsFulfilled', () => {
20
19
  });
21
20
 
22
21
  it('should return a promise', () => {
23
- const aFulfilledPromise = Bluebird.resolve('a value');
22
+ const aFulfilledPromise = Promise.resolve('a value');
24
23
 
25
24
  const result = sut.matches(aFulfilledPromise);
26
25
 
@@ -29,7 +28,7 @@ describe('IsFulfilled', () => {
29
28
  });
30
29
 
31
30
  it('should match fulfilled promises', () => {
32
- const aFulfilledPromise = Bluebird.resolve('a value');
31
+ const aFulfilledPromise = Promise.resolve('a value');
33
32
 
34
33
  return sut.matches(aFulfilledPromise).then((value) => {
35
34
  assert.ok(value);
@@ -37,7 +36,7 @@ describe('IsFulfilled', () => {
37
36
  });
38
37
 
39
38
  it('should not match rejected promises', () => {
40
- const aRejectedPromise = Bluebird.reject(new Error('rejected for a reason'));
39
+ const aRejectedPromise = Promise.reject(new Error('rejected for a reason'));
41
40
 
42
41
  return sut.matches(aRejectedPromise).then((value) => {
43
42
  assert.equal(value, false);
@@ -46,14 +45,14 @@ describe('IsFulfilled', () => {
46
45
 
47
46
  it('should wait for pending promises', (done) => {
48
47
  let resolveFn;
49
- const deferred = new Bluebird((resolve) => {
48
+ const deferred = new Promise((resolve) => {
50
49
  resolveFn = resolve;
51
50
  });
52
51
 
53
52
  sut.matches(deferred).then((value) => {
54
53
  assert.ok(value);
55
54
  })
56
- .nodeify(done);
55
+ .then(done, done);
57
56
 
58
57
  resolveFn();
59
58
  });
@@ -74,7 +73,7 @@ describe('IsFulfilled', () => {
74
73
  });
75
74
 
76
75
  it('should return a promise', () => {
77
- const aFulfilledPromise = Bluebird.resolve('a value');
76
+ const aFulfilledPromise = Promise.resolve('a value');
78
77
 
79
78
  const result = sut.matches(aFulfilledPromise);
80
79
 
@@ -83,7 +82,7 @@ describe('IsFulfilled', () => {
83
82
  });
84
83
 
85
84
  it('should match fulfilled promise with equivalent value', () => {
86
- const aFulfilledPromise = Bluebird.resolve('a value');
85
+ const aFulfilledPromise = Promise.resolve('a value');
87
86
 
88
87
  return sut.matches(aFulfilledPromise).then((value) => {
89
88
  assert.ok(value);
@@ -91,7 +90,7 @@ describe('IsFulfilled', () => {
91
90
  });
92
91
 
93
92
  it('should not match fulfilled promise with different value', () => {
94
- const aFulfilledPromise = Bluebird.resolve('another value');
93
+ const aFulfilledPromise = Promise.resolve('another value');
95
94
 
96
95
  return sut.matches(aFulfilledPromise).then((value) => {
97
96
  assert.equal(value, false);
@@ -99,7 +98,7 @@ describe('IsFulfilled', () => {
99
98
  });
100
99
 
101
100
  it('should not match rejected promise', () => {
102
- const aRejectedPromise = Bluebird.reject(new Error('a value'));
101
+ const aRejectedPromise = Promise.reject(new Error('a value'));
103
102
 
104
103
  return sut.matches(aRejectedPromise).then((value) => {
105
104
  assert.equal(value, false);
@@ -108,14 +107,14 @@ describe('IsFulfilled', () => {
108
107
 
109
108
  it('should wait for pending promises', (done) => {
110
109
  let resolveFn;
111
- const deferred = new Bluebird((resolve) => {
110
+ const deferred = new Promise((resolve) => {
112
111
  resolveFn = resolve;
113
112
  });
114
113
 
115
114
  sut.matches(deferred).then((value) => {
116
115
  assert.ok(value);
117
116
  })
118
- .nodeify(done);
117
+ .then(done, done);
119
118
 
120
119
  resolveFn('a value');
121
120
  });
@@ -134,7 +133,7 @@ describe('IsFulfilled', () => {
134
133
  });
135
134
 
136
135
  it('should contain mismatched value', () => {
137
- const actual = Bluebird.resolve('another value');
136
+ const actual = Promise.resolve('another value');
138
137
 
139
138
  return sut.describeMismatch(actual, description).then(() => {
140
139
  __.assertThat(description.get(), __.equalTo('fulfillment value: was "another value"'));
@@ -142,7 +141,7 @@ describe('IsFulfilled', () => {
142
141
  });
143
142
 
144
143
  it('should contain rejected reason', () => {
145
- const actual = Bluebird.reject(new Error('for a reason'));
144
+ const actual = Promise.reject(new Error('for a reason'));
146
145
 
147
146
  return sut.describeMismatch(actual, description).then(() => {
148
147
  __.assertThat(description.get(), __.allOf(__.containsString('was'), __.containsString('rejected'), __.containsString('"for a reason"')));
@@ -158,7 +157,7 @@ describe('IsFulfilled', () => {
158
157
  });
159
158
 
160
159
  it('should match fulfilled promise with matching values', () => {
161
- const aFulfilledPromise = Bluebird.resolve('expected value');
160
+ const aFulfilledPromise = Promise.resolve('expected value');
162
161
 
163
162
  return sut.matches(aFulfilledPromise).then((value) => {
164
163
  assert.ok(value);
@@ -166,7 +165,7 @@ describe('IsFulfilled', () => {
166
165
  });
167
166
 
168
167
  it('should not match fulfilled promise with nonmatching value', () => {
169
- const aFulfilledPromise = Bluebird.resolve('another value');
168
+ const aFulfilledPromise = Promise.resolve('another value');
170
169
 
171
170
  return sut.matches(aFulfilledPromise).then((value) => {
172
171
  assert.equal(value, false);
@@ -174,7 +173,7 @@ describe('IsFulfilled', () => {
174
173
  });
175
174
 
176
175
  it('should not match rejected promise', () => {
177
- const aRejectedPromise = Bluebird.reject(new Error('rejected for expected reason'));
176
+ const aRejectedPromise = Promise.reject(new Error('rejected for expected reason'));
178
177
 
179
178
  return sut.matches(aRejectedPromise).then((value) => {
180
179
  assert.equal(value, false);
@@ -183,14 +182,14 @@ describe('IsFulfilled', () => {
183
182
 
184
183
  it('should wait for pending promises', (done) => {
185
184
  let resolveFn;
186
- const deferred = new Bluebird((resolve) => {
185
+ const deferred = new Promise((resolve) => {
187
186
  resolveFn = resolve;
188
187
  });
189
188
 
190
189
  sut.matches(deferred).then((value) => {
191
190
  assert.ok(value);
192
191
  })
193
- .nodeify(done);
192
+ .then(done, done);
194
193
 
195
194
  resolveFn('expected value');
196
195
  });
@@ -209,7 +208,7 @@ describe('IsFulfilled', () => {
209
208
  });
210
209
 
211
210
  it('should contain mismatched value', () => {
212
- const actual = Bluebird.resolve('another value');
211
+ const actual = Promise.resolve('another value');
213
212
 
214
213
  return sut.describeMismatch(actual, description).then(() => {
215
214
  __.assertThat(description.get(), __.equalTo('fulfillment value: was "another value"'));
@@ -222,7 +221,7 @@ describe('IsFulfilled', () => {
222
221
  other: 'property'
223
222
  }));
224
223
 
225
- const actual = Bluebird.resolve({expected: 'another value', other: 'property'});
224
+ const actual = Promise.resolve({expected: 'another value', other: 'property'});
226
225
 
227
226
  return sut.describeMismatch(actual, description).then(() => {
228
227
  __.assertThat(description.get(), __.equalTo('fulfillment value: expected was "another value"'));
@@ -230,7 +229,7 @@ describe('IsFulfilled', () => {
230
229
  });
231
230
 
232
231
  it('should contain rejected reason', () => {
233
- const actual = Bluebird.reject(new Error('for a reason'));
232
+ const actual = Promise.reject(new Error('for a reason'));
234
233
 
235
234
  return sut.describeMismatch(actual, description).then(() => {
236
235
  __.assertThat(description.get(), __.allOf(__.containsString('was'), __.containsString('rejected'), __.containsString('"for a reason"')));
@@ -246,8 +245,8 @@ describe('IsFulfilled', () => {
246
245
  });
247
246
 
248
247
  it('should match fulfilled promise with matching values', () => {
249
- const aFulfilledPromise = Bluebird.resolve([
250
- Bluebird.resolve('expected')
248
+ const aFulfilledPromise = Promise.resolve([
249
+ Promise.resolve('expected')
251
250
  ]);
252
251
 
253
252
  return sut.matches(aFulfilledPromise).then((value) => {
@@ -256,8 +255,8 @@ describe('IsFulfilled', () => {
256
255
  });
257
256
 
258
257
  it('should not match fulfilled promise with nonmatching value', () => {
259
- const aFulfilledPromise = Bluebird.resolve([
260
- Bluebird.resolve('another value')
258
+ const aFulfilledPromise = Promise.resolve([
259
+ Promise.resolve('another value')
261
260
  ]);
262
261
 
263
262
  return sut.matches(aFulfilledPromise).then((value) => {
@@ -267,15 +266,15 @@ describe('IsFulfilled', () => {
267
266
 
268
267
  it('should wait for pending promises', (done) => {
269
268
  let resolveFn;
270
- const deferred = new Bluebird((resolve) => {
269
+ const deferred = new Promise((resolve) => {
271
270
  resolveFn = resolve;
272
271
  });
273
- const aFulfilledPromiseContainingAPendingPromise = Bluebird.resolve([deferred]);
272
+ const aFulfilledPromiseContainingAPendingPromise = Promise.resolve([deferred]);
274
273
 
275
274
  sut.matches(aFulfilledPromiseContainingAPendingPromise).then((value) => {
276
275
  assert.ok(value);
277
276
  })
278
- .nodeify(done);
277
+ .then(done, done);
279
278
 
280
279
  resolveFn('expected');
281
280
  });
@@ -295,7 +294,7 @@ describe('IsFulfilled', () => {
295
294
 
296
295
  it('should contain mismatch description', () => {
297
296
 
298
- const actual = Bluebird.resolve([Bluebird.resolve('another value')]);
297
+ const actual = Promise.resolve([Promise.resolve('another value')]);
299
298
 
300
299
  return sut.describeMismatch(actual, description).then(() => {
301
300
  __.assertThat(description.get(), __.equalTo('fulfillment value: item 0: fulfillment value: was "another value"\n'));
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const assert = require('assert');
4
- const Bluebird = require('bluebird');
5
4
 
6
5
  const __ = require('../../..');
7
6
 
@@ -15,20 +14,20 @@ describe('IsPromise', () => {
15
14
  });
16
15
 
17
16
  it('should match fulfilled promises', () => {
18
- const aFulfilledPromise = Bluebird.resolve('a value');
17
+ const aFulfilledPromise = Promise.resolve('a value');
19
18
 
20
19
  assert.ok(sut.matches(aFulfilledPromise));
21
20
  });
22
21
 
23
22
  it('should match rejected promises', () => {
24
- const aRejectedPromise = Bluebird.reject(new Error('rejected for a reason'));
23
+ const aRejectedPromise = Promise.reject(new Error('rejected for a reason'));
25
24
  aRejectedPromise.catch(() => null);
26
25
 
27
26
  assert.ok(sut.matches(aRejectedPromise));
28
27
  });
29
28
 
30
29
  it('should match pending promises', () => {
31
- const aPendingPromise = new Bluebird(() => {});
30
+ const aPendingPromise = new Promise(() => {});
32
31
 
33
32
  assert.ok(sut.matches(aPendingPromise));
34
33
  });
@@ -2,7 +2,6 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const assert = require('assert');
5
- const Bluebird = require('bluebird');
6
5
 
7
6
  const __ = require('../../..');
8
7
 
@@ -20,7 +19,7 @@ describe('IsRejected', () => {
20
19
  });
21
20
 
22
21
  it('should return a promise', () => {
23
- const aFulfilledPromise = Bluebird.resolve('a value');
22
+ const aFulfilledPromise = Promise.resolve('a value');
24
23
 
25
24
  const result = sut.matches(aFulfilledPromise);
26
25
 
@@ -29,7 +28,7 @@ describe('IsRejected', () => {
29
28
  });
30
29
 
31
30
  it('should not match fulfilled promises', () => {
32
- const aFulfilledPromise = Bluebird.resolve('a value');
31
+ const aFulfilledPromise = Promise.resolve('a value');
33
32
 
34
33
  return sut.matches(aFulfilledPromise).then((value) => {
35
34
  assert.equal(value, false);
@@ -37,7 +36,7 @@ describe('IsRejected', () => {
37
36
  });
38
37
 
39
38
  it('should match rejected promises', () => {
40
- const aRejectedPromise = Bluebird.reject(new Error('rejected for a reason'));
39
+ const aRejectedPromise = Promise.reject(new Error('rejected for a reason'));
41
40
 
42
41
  return sut.matches(aRejectedPromise).then((value) => {
43
42
  assert.ok(value);
@@ -46,14 +45,14 @@ describe('IsRejected', () => {
46
45
 
47
46
  it('should wait for pending promises', (done) => {
48
47
  let rejectFn;
49
- const deferred = new Bluebird((__resolve, reject) => {
48
+ const deferred = new Promise((__resolve, reject) => {
50
49
  rejectFn = reject;
51
50
  });
52
51
 
53
52
  sut.matches(deferred).then((value) => {
54
53
  assert.ok(value);
55
54
  })
56
- .nodeify(done);
55
+ .then(done, done);
57
56
 
58
57
  rejectFn(new Error());
59
58
  });
@@ -74,7 +73,7 @@ describe('IsRejected', () => {
74
73
  });
75
74
 
76
75
  it('should return a promise', () => {
77
- const aFulfilledPromise = Bluebird.resolve('a value');
76
+ const aFulfilledPromise = Promise.resolve('a value');
78
77
 
79
78
  const result = sut.matches(aFulfilledPromise);
80
79
 
@@ -83,7 +82,7 @@ describe('IsRejected', () => {
83
82
  });
84
83
 
85
84
  it('should not match fulfilled promise with matching value', () => {
86
- const aFulfilledPromise = Bluebird.resolve(new Error('a reason'));
85
+ const aFulfilledPromise = Promise.resolve(new Error('a reason'));
87
86
 
88
87
  return sut.matches(aFulfilledPromise).then((value) => {
89
88
  assert.equal(value, false);
@@ -91,7 +90,7 @@ describe('IsRejected', () => {
91
90
  });
92
91
 
93
92
  it('should match rejected promise with same reason', () => {
94
- const aRejectedPromise = Bluebird.reject(new Error('a reason'));
93
+ const aRejectedPromise = Promise.reject(new Error('a reason'));
95
94
 
96
95
  return sut.matches(aRejectedPromise).then((value) => {
97
96
  assert.ok(value);
@@ -99,7 +98,7 @@ describe('IsRejected', () => {
99
98
  });
100
99
 
101
100
  it('should not match rejected promise with different reason', () => {
102
- const aRejectedPromise = Bluebird.reject(new Error('another reason'));
101
+ const aRejectedPromise = Promise.reject(new Error('another reason'));
103
102
  aRejectedPromise.catch(() => null);
104
103
 
105
104
  return sut.matches(aRejectedPromise).then((value) => {
@@ -109,14 +108,14 @@ describe('IsRejected', () => {
109
108
 
110
109
  it('should wait for pending promises', (done) => {
111
110
  let rejectFn;
112
- const deferred = new Bluebird((__resolve, reject) => {
111
+ const deferred = new Promise((__resolve, reject) => {
113
112
  rejectFn = reject;
114
113
  });
115
114
 
116
115
  sut.matches(deferred).then((value) => {
117
116
  assert.ok(value);
118
117
  })
119
- .nodeify(done);
118
+ .then(done, done);
120
119
 
121
120
  rejectFn(new Error('a reason'));
122
121
  });
@@ -135,7 +134,7 @@ describe('IsRejected', () => {
135
134
  });
136
135
 
137
136
  it('should contain fulfilled value', () => {
138
- const actual = Bluebird.resolve('a value');
137
+ const actual = Promise.resolve('a value');
139
138
 
140
139
  return sut.describeMismatch(actual, description).then(() => {
141
140
  __.assertThat(description.get(), __.allOf(__.containsString('was'), __.containsString('fulfilled'), __.containsString('"a value"')));
@@ -143,7 +142,7 @@ describe('IsRejected', () => {
143
142
  });
144
143
 
145
144
  it('should contain mismatched reason', () => {
146
- const actual = Bluebird.reject(new Error('another reason'));
145
+ const actual = Promise.reject(new Error('another reason'));
147
146
 
148
147
  return sut.describeMismatch(actual, description).then(() => {
149
148
  __.assertThat(description.get(), __.equalTo('rejection value message was "another reason"'));
@@ -159,7 +158,7 @@ describe('IsRejected', () => {
159
158
  });
160
159
 
161
160
  it('should return a promise', () => {
162
- const aFulfilledPromise = Bluebird.resolve('a value');
161
+ const aFulfilledPromise = Promise.resolve('a value');
163
162
 
164
163
  const result = sut.matches(aFulfilledPromise);
165
164
 
@@ -168,7 +167,7 @@ describe('IsRejected', () => {
168
167
  });
169
168
 
170
169
  it('should not match fulfilled promise with matching value', () => {
171
- const aFulfilledPromise = Bluebird.resolve(new Error('expected value'));
170
+ const aFulfilledPromise = Promise.resolve(new Error('expected value'));
172
171
 
173
172
  return sut.matches(aFulfilledPromise).then((value) => {
174
173
  assert.equal(value, false);
@@ -176,7 +175,7 @@ describe('IsRejected', () => {
176
175
  });
177
176
 
178
177
  it('should match rejected promises with matching reason', () => {
179
- const aRejectedPromise = Bluebird.reject(new Error('rejected for expected reason'));
178
+ const aRejectedPromise = Promise.reject(new Error('rejected for expected reason'));
180
179
 
181
180
  return sut.matches(aRejectedPromise).then((value) => {
182
181
  assert.ok(value);
@@ -184,7 +183,7 @@ describe('IsRejected', () => {
184
183
  });
185
184
 
186
185
  it('should not match rejected promises with different reason', () => {
187
- const aRejectedPromise = Bluebird.reject(new Error('rejected for a reason'));
186
+ const aRejectedPromise = Promise.reject(new Error('rejected for a reason'));
188
187
 
189
188
  return sut.matches(aRejectedPromise).then((value) => {
190
189
  assert.equal(value, false);
@@ -193,14 +192,14 @@ describe('IsRejected', () => {
193
192
 
194
193
  it('should wait for pending promises', (done) => {
195
194
  let rejectFn;
196
- const deferred = new Bluebird((__resolve, reject) => {
195
+ const deferred = new Promise((__resolve, reject) => {
197
196
  rejectFn = reject;
198
197
  });
199
198
 
200
199
  sut.matches(deferred).then((value) => {
201
200
  assert.ok(value);
202
201
  })
203
- .nodeify(done);
202
+ .then(done, done);
204
203
 
205
204
  rejectFn(new Error('expected reason'));
206
205
  });
@@ -220,7 +219,7 @@ describe('IsRejected', () => {
220
219
  });
221
220
 
222
221
  it('should contain fulfilled value', () => {
223
- const actual = Bluebird.resolve('a value');
222
+ const actual = Promise.resolve('a value');
224
223
 
225
224
  return sut.describeMismatch(actual, description).then(() => {
226
225
  __.assertThat(description.get(), __.allOf(__.containsString('was'), __.containsString('fulfilled'), __.containsString('"a value"')));
@@ -228,7 +227,7 @@ describe('IsRejected', () => {
228
227
  });
229
228
 
230
229
  it('should contain mismatched description', () => {
231
- const actual = Bluebird.reject(new Error('another reason'));
230
+ const actual = Promise.reject(new Error('another reason'));
232
231
 
233
232
  return sut.describeMismatch(actual, description).then(() => {
234
233
  __.assertThat(description.get(), __.equalTo('rejection value message was "another reason"'));
@@ -2,7 +2,6 @@
2
2
 
3
3
  const _ = require('lodash');
4
4
  const AssertionError = require('assertion-error');
5
- const Bluebird = require('bluebird');
6
5
 
7
6
  const __ = require('../..');
8
7
  const TestMatcher = require('./TestMatcher');
@@ -16,113 +15,80 @@ describe('promiseThat', () => {
16
15
  __.assertThat(result, __.is(__.promise()));
17
16
  });
18
17
 
19
- it('should pass given value to matcher', (done) => {
18
+ it('should pass given value to matcher', async () => {
20
19
  let passedValue;
21
20
 
22
- __.promiseThat('a value', new TestMatcher((value) => {
21
+ await __.promiseThat('a value', new TestMatcher((value) => {
23
22
  passedValue = value;
24
23
  return true;
25
- })).done(
26
- () => {
27
- __.assertThat(passedValue, __.is('a value'));
28
- done();
29
- },
30
- () => {
31
- throw new Error('Should not be rejected');
32
- }
33
- );
24
+ }));
25
+ __.assertThat(passedValue, __.is('a value'));
34
26
  });
35
27
 
36
- it('should fulfill promise if matcher matches', (done) => {
28
+ it('should fulfill promise if matcher matches', async () => {
37
29
  const input = 'expected value';
38
30
 
39
- __.promiseThat(input, __.is('expected value')).done(
40
- () => {
41
- done();
42
- },
43
- () => {
44
- throw new Error('Should not be rejected');
45
- }
46
- );
31
+ await __.promiseThat(input, __.is('expected value'));
47
32
  });
48
33
 
49
- it('should resolve if matcher returns promise resolving to true', (done) => {
34
+ it('should resolve if matcher returns promise resolving to true', async () => {
50
35
 
51
- __.promiseThat('a value', new TestMatcher(() => {
52
- return Bluebird.resolve(true);
53
- })).done(
54
- () => {
55
- done();
56
- },
57
- () => {
58
- throw new Error('Should not be rejected');
59
- }
60
- );
36
+ await __.promiseThat('a value', new TestMatcher(() => {
37
+ return Promise.resolve(true);
38
+ }));
61
39
  });
62
40
 
63
- it('should reject promise with AssertionError if matcher resolves to false', (done) => {
41
+ it('should reject promise with AssertionError if matcher resolves to false', async () => {
64
42
 
65
- __.promiseThat('a value', new TestMatcher(() => {
66
- return Bluebird.resolve(false);
67
- })).done(
68
- () => {
69
- throw new Error('Should not be fulfilled');
70
- },
71
- (reason) => {
72
- __.assertThat(reason, __.instanceOf(AssertionError));
73
- done();
74
- }
75
- );
43
+ try {
44
+ await __.promiseThat('a value', new TestMatcher(() => Promise.resolve(false)));
45
+ throw new Error('Should not be fulfilled');
46
+ } catch (e) {
47
+ __.assertThat(e, __.instanceOf(AssertionError));
48
+ }
76
49
  });
77
50
 
78
51
  it('should defer result until matcher promise resolves', (done) => {
79
52
  let resolveFn;
80
- const deferred = new Bluebird((resolve) => {
53
+ const deferred = new Promise((resolve) => {
81
54
  resolveFn = resolve;
82
55
  });
83
56
 
84
57
  __.promiseThat('a value', new TestMatcher(() => {
85
58
  return deferred;
86
59
  }))
87
- .nodeify(done);
60
+ .then(done, done);
88
61
 
89
62
  resolveFn(true);
90
63
  });
91
64
 
92
- it('should allow a message as first parameter', () => {
65
+ it('should allow a message as first parameter', async () => {
93
66
  const message = 'Some explanation';
94
67
 
95
- return __.promiseThat(message, 'different value', __.is('expected value')).then(
96
- () => {
97
- throw new Error('Should not be fulfilled');
98
- },
99
- (reason) => {
100
- __.assertThat(reason, __.instanceOf(AssertionError));
101
- __.assertThat(reason.message, __.containsString(message));
102
- }
103
- );
68
+ try {
69
+ await __.promiseThat(message, 'different value', __.is('expected value'));
70
+ throw new Error('Should not be fulfilled');
71
+ } catch (e) {
72
+ __.assertThat(e, __.instanceOf(AssertionError));
73
+ __.assertThat(e.message, __.containsString(message));
74
+ }
104
75
  });
105
76
 
106
- it('should forward rejection if matcher returns rejecting promise', () => {
77
+ it('should forward rejection if matcher returns rejecting promise', async () => {
107
78
  const rejectionValue = new Error('some reason');
108
- const rejectingMatcher = new TestMatcher(() => {
109
- return Bluebird.reject(rejectionValue);
110
- });
111
-
112
- return __.promiseThat('a value', rejectingMatcher)
113
- .then(
114
- () => {
115
- throw new Error('Should not be fulfilled');
116
- },
117
- (reason) => {
118
- __.assertThat(reason, __.is(rejectionValue));
119
- }
120
- );
79
+ const rejectingMatcher = new TestMatcher(() => Promise.reject(rejectionValue));
80
+
81
+ try {
82
+ await __.promiseThat('a value', rejectingMatcher);
83
+ throw new Error('Should not be fulfilled');
84
+ } catch (e) {
85
+ __.assertThat(e, __.is(rejectionValue));
86
+ }
121
87
  });
122
88
 
123
89
  it('should allow matchers to describe mismatch asynchronously', (done) => {
124
90
  let resolveFn;
125
- const deferred = new Bluebird((resolve) => {
91
+ const deferred = new Promise((resolve) => {
126
92
  resolveFn = resolve;
127
93
  });
128
94
  const matcher = _.create(new __.Matcher(), {
@@ -148,31 +114,28 @@ describe('promiseThat', () => {
148
114
  __.assertThat(reason.message, __.containsString('Deferred mismatch description'));
149
115
  }
150
116
  )
151
- .nodeify(done);
117
+ .then(done, done);
152
118
 
153
119
  resolveFn();
154
120
  });
155
121
 
156
- it('should pass diff representations to AssertionError', (done) => {
122
+ it('should pass diff representations to AssertionError', async () => {
157
123
  const testMatcher = new TestMatcher(() => { return false; });
158
124
  testMatcher.getExpectedForDiff = () => {
159
125
  return 'expected for diff';
160
126
  };
161
127
  testMatcher.formatActualForDiff = function (actual) {
162
- return Bluebird.resolve('actual for diff: ' + actual);
128
+ return Promise.resolve('actual for diff: ' + actual);
163
129
  };
164
130
 
165
- __.promiseThat('actual value', testMatcher).done(
166
- () => {
167
- throw new Error('Should not be fulfilled');
168
- },
169
- (reason) => {
170
- __.assertThat(reason, __.hasProperties({
171
- expected: 'expected for diff',
172
- actual: 'actual for diff: actual value'
173
- }));
174
- done();
175
- }
176
- );
131
+ try {
132
+ await __.promiseThat('actual value', testMatcher);
133
+ throw new Error('Should not be fulfilled');
134
+ } catch (e) {
135
+ __.assertThat(e, __.hasProperties({
136
+ expected: 'expected for diff',
137
+ actual: 'actual for diff: actual value'
138
+ }));
139
+ }
177
140
  });
178
141
  });