Jump to content

Module:Mock title/testcases

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mr. Stradivarius (talk | contribs) at 02:47, 28 February 2021 (add tests for MockTitle argument type errors). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local mMockTitle = require("Module:Mock title")
local ScribuntoUnit = require("Module:ScribuntoUnit")

local suite = ScribuntoUnit:new()

--------------------------------------------------------------------------------
-- MockTitle tests
--------------------------------------------------------------------------------

local pageNames = {
	"Example",
	"fr:Example",
	"Module:Sandbox",
	"Module:Sandbox/subpage",
	"mw:Test",
	"fr:b:Example",
}

for _, pageName in ipairs(pageNames) do
	suite[string.format('test MockTitle: when using page name "%s", the prefixedText property equals the page name', pageName)] = function (self)
		self:assertEquals("Example", mMockTitle.MockTitle({page = "Example"}).prefixedText)
	end
end

suite["test MockTitle: when no argument table is supplied, an error is raised"] = function (self)
	self:assertThrows(
		function () mMockTitle.MockTitle() end,
		"bad argument #1 to 'MockTitle' (string expected, got nil)"
	)
end

suite["test MockTitle: when no page argument is supplied, an error is raised"] = function (self)
	self:assertThrows(
		function () mMockTitle.MockTitle{} end,
		"bad named argument page to 'MockTitle' (string expected, got nil)"
	)
end

return suite