[ospec] record errors thrown in tests as failures

This commit is contained in:
Pierre-Yves Gérardy 2018-06-01 13:42:14 +02:00 committed by Pierre-Yves Gérardy
parent 53597871b8
commit a23216b987
2 changed files with 32 additions and 6 deletions

View file

@ -179,12 +179,18 @@ else window.o = m()
startTimer()
}
} else {
var p = fn()
if (p && p.then) {
startTimer()
p.then(function() { done() }, done)
} else {
nextTickish(next)
try{
var p = fn()
if (p && p.then) {
startTimer()
p.then(function() { done() }, done)
} else {
nextTickish(next)
}
} catch (e) {
if (task.err != null) finalizeAsync(e)
// The errors of internal tasks (which don't have an Err) are ospec bugs and must be rethrown.
else throw e
}
}
globalTimeout = noTimeoutRightNow

View file

@ -281,6 +281,26 @@ o.spec("ospec", function() {
})
})
o.spec("throwing in test context is recoreded as a failure", function() {
var oo
o.beforeEach(function(){oo = o.new()})
o.afterEach(function() {
oo.run(function(results) {
o(results.length).equals(1)
o(results[0].pass).equals(false)
})
})
o("sync test", function() {
oo("throw in sync test", function() {throw new Error})
})
o("async test", function() {
oo("throw in async test", function(done) {
throw new Error
done() // eslint-disable-line no-unreachable
})
})
})
o.spec("timeout", function () {
o("when using done()", function(done) {
var oo = o.new()