Created
August 8, 2017 22:24
-
-
Save collin/aad9dfc943c9bde1044672d7579312a4 to your computer and use it in GitHub Desktop.
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
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd point out that
then
andcatch
have different behavior –then
will pass the test,catch
fail the test.