This module contains testcases for its parent module, Error.
See also
-- Unit tests for [[Module:Error]] to be executed by [[Module:Testharness]].
-- Test results are available on [[Module talk:Error/testcases]].
return {
error = {
options = {
mode = 'method',
nowiki = true
},
tests = {
-- Test error as if it were invoked with a frame argument.
{
-- It should throw an error when invoked without arguments.
{ args = {} },
'no message specified',
{ err = true }
},
{
-- It should accept empty error messages.
{ args = { '' } },
'<strong class="error"></strong>'
},
{
-- It should accept regular error messages.
{ args = { 'test' } },
'<strong class="error">test</strong>'
},
{
-- It should accept error messages passed via named parameter.
{ args = { message = 'test' } },
'<strong class="error">test</strong>'
},
{
-- It should prioritize messages passed via named parameter.
{ args = { 'foo', message = 'bar' } },
'<strong class="error">bar</strong>'
},
{
-- It should throw an error if tag is specified but no message.
{ args = { tag = 'div' } },
'no message specified',
{ err = true }
},
{
-- It should render the error in with <div>.
{ args = { '', tag = 'div'} },
'<div class="error"></div>'
},
{
-- It should render the error with <p>.
{ args = { '', tag = 'p'} },
'<p class="error"></p>'
},
{
-- It should render the error with <span>.
{ args = { '', tag = 'span' } },
'<span class="error"></span>'
},
{
-- It should render the error with strong tags.
{ args = { '', tag = 'strong' } },
'<strong class="error"></strong>'
},
{
-- It should always render lowercase tags.
{ args = { '', tag = 'DIV' } },
'<div class="error"></div>'
},
{
-- It should fall use <strong> if no valid tag was specified.
{ args = { '', tag = '' } },
'<strong class="error"></strong>'
},
{
-- It should fall use <strong> if no valid tag was specified.
{ args = { '', tag = 'tag' } },
'<strong class="error"></strong>'
},
{
-- It should fall use <strong> if no valid tag was specified.
{ args = { '', tag = '<div>'} },
'<strong class="error"></strong>'
},
{
-- It should accept a numbered message and named tag.
{ args = { 'test', tag = 'div' } },
'<div class="error">test</div>'
},
{
-- It should accept a named message and named tag.
{ args = { message = 'test', tag = 'div' } },
'<div class="error">test</div>'
},
{
-- It should output wikitext as entered.
{ args = { '[[Foo|bar]]' } },
'<strong class="error">[[Foo|bar]]</strong>'
},
{
-- It should output HTML as entered.
{ args = { '<code>test</code>' } },
'<strong class="error"><code>test</code></strong>'
},
-- Test error as if it were called from another Lua module.
{
-- It should throw an error if no message was specified.
{}, 'no message specified', { err = true }
},
{
-- It should accept a message passed via numbered parameter.
{ 'test' }, '<strong class="error">test</strong>'
},
{
-- It should accept a message passed via named parameter.
{ message = 'test' }, '<strong class="error">test</strong>'
},
{
-- It should throw an error if tag was specified but no message.
{ tag = 'div' }, 'no message specified', { err = true }
},
{
-- It should accept a numbered message and a named tag.
{ 'test', tag = 'div' }, '<div class="error">test</div>'
},
{
-- It should accept a named message and a named tag.
{ message = 'test', tag = 'div'},
'<div class="error">test</div>'
}
}
}
}