Skip to content

Instantly share code, notes, and snippets.

@bassjacob
Created April 20, 2017 02:47
Show Gist options
  • Save bassjacob/2abff58e7edf4a4b565206f796c41622 to your computer and use it in GitHub Desktop.
Save bassjacob/2abff58e7edf4a4b565206f796c41622 to your computer and use it in GitHub Desktop.
a simple shim for ava's it.failing function
function failing (ctx, name, fn) {
const error = () => { throw new Error('remove the failing bit') };
if (fn.length > 0) {
return ctx(name, function (done) {
fn(function(err) {
if (!err) {
return done(error());
}
return done();
});
});
}
return ctx(name, function () {
try {
const retVal = fn();
if (retVal && typeof retVal.then === 'function') {
return retVal.then(() => Promise.reject(error()), () => Promise.resolve());
}
} catch (e) {
return;
}
error();
});
}
describe('outer', function () {
failing(it, "promise fail", function () {
return Promise.reject();
});
failing(it, "promise succeed", function () {
return Promise.resolve();
});
failing(it, "callback fail", function (done) {
done(new Error());
});
failing(it, "callback succeed", function (done) {
done();
});
failing(it, "sync fail", function () {
throw new Error();
});
failing(it, "sync succeed", function () {
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment