siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
40 lines (31 loc) • 1.06 kB
JavaScript
StartTest(function (t) {
// this function performs an asynchronous addition of 1st argument to second
var asynchronousFunction = function (a, b, callback, errback) {
setTimeout(function () {
var res = a + b
if (isNaN(res)) {
errback(res)
} else {
callback(res)
}
}, 10)
};
t.it("Testing arbitrary asynchronous function", function (t) {
var async1 = t.beginAsync()
asynchronousFunction(1, 1, function (res) {
t.endAsync(async1)
t.is(res, 2, 'Correct result of 1 plus 1')
}, function () {
t.fail("Should never get here")
})
})
t.it("Testing arbitrary asynchronous function", function (t) {
var async2 = t.beginAsync()
asynchronousFunction(1, {}, function () {
t.fail("Should never get here")
}, function (res) {
t.endAsync(async2)
t.ok(isNaN(res), '1 plus {} is not a number')
})
})
})