Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. Apply this transform using jscodeshift to remove most chai-as-promised assertions.
  2.  
  3. > Note: this codemod does not cover all of the `assert.eventually` cases, but they should be easy to add.
  4.  
  5. There's really no alternative to defining the function `assert.isRejected`. The following should approximate the functionallity from chai-as-promised.
  6.  
  7. ```js
  8. var chai = require('chai');
  9.  
  10. Assertion.addMethod('isRejected', function expectedRejection(promise, expected) {
  11. return promise
  12. .then(function(actual) {
  13. this.assert(
  14. false,
  15. 'expected #{this} to be rejected but it was fulfilled with #{act}',
  16. null,
  17. expected,
  18. actual
  19. );
  20. return actual;
  21. }.bind(this),
  22. function(reason) {
  23. if (expected) {
  24. if (expected instanceof RegExp || typeof expected === 'string') {
  25. this.match(reason, expected);
  26. }
  27.  
  28. if (expected instanceof Error) {
  29. this.instanceOf(reason, expected);
  30. }
  31.  
  32.  
  33. }
  34. }.bind(this));
  35. });
  36. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement