mirror of
https://github.com/kikito/cron.lua.git
synced 2024-12-19 18:34:20 +00:00
Write some tests for the new function.
This commit is contained in:
parent
0c1f7a5e88
commit
0f4bc8fd53
@ -109,6 +109,37 @@ describe( 'cron', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('.doFor', function()
|
||||
it('Throws errors if time is not a positive number, or callback is not function', function()
|
||||
assert_error(function() cron.every('error', count) end)
|
||||
assert_error(function() cron.every(2, 'error') end)
|
||||
assert_error(function() cron.every(-2, count) end)
|
||||
assert_error(function() cron.every(-2, {}) end)
|
||||
assert_not_error(function() cron.every(2, count) end)
|
||||
assert_not_error(function() cron.every(2, countable) end)
|
||||
end)
|
||||
|
||||
it('Executes actions on every update until the timer expires', function()
|
||||
cron.doFor(5, count)
|
||||
assert_equal(counter, 0)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 1)
|
||||
cron.update(3)
|
||||
assert_equal(counter, 2)
|
||||
cron.update(3)
|
||||
assert_equal(counter, 3)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 3)
|
||||
end)
|
||||
|
||||
it('Respects parameters', function()
|
||||
cron.doFor(4, count, 2)
|
||||
cron.update(1)
|
||||
cron.update(1)
|
||||
assert_equal(counter, 4)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('.cancel', function()
|
||||
it('Cancels timed entries', function()
|
||||
local id = cron.after(1, count)
|
||||
|
Loading…
Reference in New Issue
Block a user