Test-driven development · 44 / 69
Test a rejected input
YOUR TASK
Make this happen
A function may reject invalid input with error. The raises matcher calls a supplied function and expects a catchable error. Resource exhaustion is not a catchable validation error.
Read the cases in
lesson.test.lua, then choose Check solution to see what needs to change.Update
subject.luauntil every test passes. Keep the supplied tests unchanged.
Read the starter and tests
subject.lua
exports.requirePositive = function(n: number): number return n end
lesson.test.lua
local t = require("test")
local subject = require("cococo.subject")
t.it("rejects zero", function()
local s = subject.load()
t.expect(function()
s.requirePositive(0)
end):raises()
end)
t.it("accepts positive", function()
local s = subject.load()
t.expect(s.requirePositive(3)):eq(3)
end)