Skip to content

Instantly share code, notes, and snippets.

@collin
Created August 8, 2017 22:24
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 collin/aad9dfc943c9bde1044672d7579312a4 to your computer and use it in GitHub Desktop.
Save collin/aad9dfc943c9bde1044672d7579312a4 to your computer and use it in GitHub Desktop.
const registeredTests = [];
function it (testFn) {
registeredTests.push(testFn);
}
function runTheNextTest () {
var testFunction = registeredTests.pop();
var isAsync = testFunction.length == 1;
if (isAsync) {
testFunction(function done (err) {
if (err) /* report the failure */
runTheNextTest();
});
}
else {
var maybeAPromise = testFunction();
if (isAPromise(maybeAPromise)) {
maybeAPromise
.then(runTheNextTest)
.catch(runTheNextTest);
}
else {
runTheNextTest();
}
}
}
runTheNextTest();
@glebec
Copy link

glebec commented Aug 8, 2017

I'd point out that then and catch have different behavior – then will pass the test, catch fail the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment