Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Apply this transform using jscodeshift to remove most chai-as-promised assertions.
- > Note: this codemod does not cover all of the `assert.eventually` cases, but they should be easy to add.
- There's really no alternative to defining the function `assert.isRejected`. The following should approximate the functionallity from chai-as-promised.
- ```js
- var chai = require('chai');
- Assertion.addMethod('isRejected', function expectedRejection(promise, expected) {
- return promise
- .then(function(actual) {
- this.assert(
- false,
- 'expected #{this} to be rejected but it was fulfilled with #{act}',
- null,
- expected,
- actual
- );
- return actual;
- }.bind(this),
- function(reason) {
- if (expected) {
- if (expected instanceof RegExp || typeof expected === 'string') {
- this.match(reason, expected);
- }
- if (expected instanceof Error) {
- this.instanceOf(reason, expected);
- }
- }
- }.bind(this));
- });
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement