Add testing helpers for dealing with multiple errors

master
4O4 2019-10-02 16:41:48 +02:00
parent 78363657ed
commit f9c29e1f17
1 changed files with 17 additions and 0 deletions

View File

@ -5,6 +5,23 @@ for _, fn in pairs({'describe', 'it', 'test', 'expect', 'spy', 'before', 'after'
_G[fn] = lust[fn]
end
-- helper function to safely accumulate errors which will be displayed when done testing
function tryCall(fn, errorsAccumulator)
local errNum = #errorsAccumulator
xpcall(fn, function (err)
table.insert(errorsAccumulator, err)
end)
return #errorsAccumulator == errNum
end
function throwErrorsIfAny(errorsAccumulator)
if #errorsAccumulator > 0 then
error(table.concat(errorsAccumulator, '\n\t' .. string.rep('\t', lust.level)))
end
end
observableSpy = function(observable)
local observer = Rx.Observer.create(_, function() end, _)
local onNext = spy(observer, '_onNext')