Skip to content

Instantly share code, notes, and snippets.

@qubyte
Last active April 20, 2016 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qubyte/45581ff9258788d815bfe51d70df99f6 to your computer and use it in GitHub Desktop.
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.
import inverter from 'promise-inverter';
// Mocha style test.
it('rejects with an error', () => {
return someRejectedPromise
.then(...inverter)
.then(err => assert.ok(err instanceof Error));
});
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));
});
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