-- Load necessary moduleslocal mCheckDYKHook = require('Module:Check DYK hook/sandbox')local ScribuntoUnit = require('Module:ScribuntoUnit')
-- Initialise test suitelocal suite = ScribuntoUnit:new
---------------------------------------------------------------------------------- Helper methods--------------------------------------------------------------------------------
local function makeFrameWithArgs(args) local frame = mw.getCurrentFrame return frame:newChildend
function suite:assertErrorMessageContains(func, expectedMessage) local success, actualMessage = pcall(func) self:assertFalse(success) self:assertStringContains(expectedMessage, actualMessage, true)end
---------------------------------------------------------------------------------- Tests for p._isValidHook--------------------------------------------------------------------------------
local moduleTestData =
for _, testData in ipairs(moduleTestData) do suite[testData.testName] = function(self) local result = mCheckDYKHook._isValidHook(testData.hook) if testData.expected then self:assertTrue(result) else self:assertFalse(result) end endend
function suite:testIsValidHook_RaisesError_WhenHookIsNotAString self:assertErrorMessageContains(function mCheckDYKHook._isValidHook(7) end, "bad argument #1 to '_isValidHook' (string expected, got number)" )end
---------------------------------------------------------------------------------- Tests for p.isValidHook--------------------------------------------------------------------------------
local templateTestData =
for _, testData in ipairs(templateTestData) do suite[testData.testName] = function(self) self:assertEquals(mCheckDYKHook.isValidHook(makeFrameWithArgs(testData.args)), testData.expected ) endend
function suite:testTemplateIsValidHook_RaisesError_WhenNoHookSupplied self:assertErrorMessageContains(function mCheckDYKHook.isValidHook(makeFrameWithArgs) end, "No hook specified" )end
return suite