chai-as-promised 7.1.1 → 7.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. package/README.md +13 -2
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -83,9 +83,9 @@ return assert.isFulfilled(promise, "optional message");
83
83
  return assert.becomes(promise, "foo", "optional message");
84
84
  return assert.doesNotBecome(promise, "foo", "optional message");
85
85
 
86
- return assert.isRejected(promise, "optional message");
87
86
  return assert.isRejected(promise, Error, "optional message");
88
- return assert.isRejected(promise, /error message matcher/, "optional message");
87
+ return assert.isRejected(promise, /error message regex matcher/, "optional message");
88
+ return assert.isRejected(promise, "substring to search error message for", "optional message");
89
89
  ```
90
90
 
91
91
  ### Progress Callbacks
@@ -179,6 +179,17 @@ it("should change the state", function (done) {
179
179
 
180
180
  Notice how `.notify(done)` is hanging directly off of `.should`, instead of appearing after a promise assertion. This indicates to Chai as Promised that it should pass fulfillment or rejection directly through to the testing framework. Thus, the above code will fail with a Chai as Promised error (`"expected promise to be fulfilled…"`) if `promise` is rejected, but will fail with a simple Chai error (`expected "before" to equal "after"`) if `otherState` does not change.
181
181
 
182
+ ### Working with `async`/`await` and Promise-Friendly Test Runners
183
+
184
+ Since any assertion that must wait on a promise returns a promise itself, if you're able to use `async`/`await` and your test runner supports returning a promise from test methods, you can await assertions in tests. In many cases you can avoid using Chai as Promised at all by performing a synchronous assertion after an `await`, but awaiting `rejectedWith` is often more convenient than using `try`/`catch` blocks without Chai as Promised:
185
+
186
+ ```javascript
187
+ it('should work well with async/await', async () => {
188
+ (await Promise.resolve(42)).should.equal(42)
189
+ await Promise.reject(new Error()).should.be.rejectedWith(Error);
190
+ });
191
+ ```
192
+
182
193
  ### Multiple Promise Assertions
183
194
 
184
195
  To perform assertions on multiple promises, use `Promise.all` to combine multiple Chai as Promised assertions:
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "promises",
12
12
  "promises-aplus"
13
13
  ],
14
- "version": "7.1.1",
14
+ "version": "7.1.2",
15
15
  "author": "Domenic Denicola <d@domenic.me> (https://domenic.me)",
16
16
  "license": "WTFPL",
17
17
  "repository": "domenic/chai-as-promised",
@@ -29,7 +29,7 @@
29
29
  "check-error": "^1.0.2"
30
30
  },
31
31
  "peerDependencies": {
32
- "chai": ">= 2.1.2 < 5"
32
+ "chai": ">= 2.1.2 < 6"
33
33
  },
34
34
  "devDependencies": {
35
35
  "chai": "^4.0.2",