Last active
April 20, 2016 09:02
-
-
Save qubyte/45581ff9258788d815bfe51d70df99f6 to your computer and use it in GitHub Desktop.
A promise inverter for testing rejected promises with promise aware unit testing libraries.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import inverter from 'promise-inverter'; | |
// Mocha style test. | |
it('rejects with an error', () => { | |
return someRejectedPromise | |
.then(...inverter) | |
.then(err => assert.ok(err instanceof Error)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { onResolve, onReject } from 'promise-inverter'; | |
// Mocha style test. | |
it('rejects with an error', () => { | |
return someRejectedPromise | |
.then(onResolve, onReject) | |
.then(err => assert.ok(err instanceof Error)); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function onResolve(resolution) { | |
var error = new Error('Promise should not resolve.'); | |
error.resolution = resolution; | |
throw error; | |
} | |
export function onReject(err) { | |
return err; | |
} | |
export default [onResolve, onReject]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment