new TestCase(methodName)
Parameters:
| Name | Type | Description |
|---|---|---|
methodName |
string | The method to run on this instantiation. |
Examples
class FooTestCase extends TestCase {
testMethod() {
// Assemble
// Act
// Assert
this.assertEqual(actual, expected, 'extra message');
}
}
const test = new FooTestCase('testMethod');
const result = test.run();
class BarTestCase extends TestCase {
testMethod() {
// Assemble
// Act
// Assert
this.assertEqual(actual, expected, 'extra message');
}
static { this.register(); }
}
testing.run();
Classes
Members
-
id :string
-
-
typeTool :module:xunit.TypeTool
-
Methods
-
addCleanup(func, …rest)
-
Register a function with arguments to run after a test.
Parameters:
Name Type Attributes Description funcfunction Function to call.
restobject <repeatable>
Arbitrary arguments to func.
-
addEqualFunc(type, func)
-
Parameters:
Name Type Description typestring As returned from
getType.funcmodule:xunit.TestCase~EqualFunc Function to call to compare that type.
-
assertEqual(first, second, msgopt)
-
Asserts that two arguments are equal.
Parameters:
Name Type Attributes Default Description firstobject First argument.
secondobject Second argument.
msgstring <optional>
'' Text to complement the failure message.
-
assertFalse(arg, msgopt)
-
Asserts that the argument is a boolean false.
Parameters:
Name Type Attributes Default Description argobject Argument to test.
msgstring <optional>
'' Text to complement the failure message.
-
assertNoRaises(func, msgopt)
-
Asserts that no exception is raised.
Useful for supplying descriptive text when verifying an error does not occur.
Parameters:
Name Type Attributes Default Description funcfunction Function to call.
msgstring <optional>
'' Text to complement the failure message.
-
assertNotEqual(first, second, msgopt)
-
Asserts that two arguments are NOT equal.
Parameters:
Name Type Attributes Default Description firstobject First argument.
secondobject Second argument.
msgstring <optional>
'' Text to complement the failure message.
-
assertRaises(exc, func, msgopt)
-
Asserts the expected exception is raised.
Parameters:
Name Type Attributes Default Description excfunction Expected Error class.
funcfunction Function to call.
msgstring <optional>
'' Text to complement the failure message.
-
assertRaisesCause(exc, cause, func, msgopt)
-
Asserts the expected exception is raised with matching cause.
Parameters:
Name Type Attributes Default Description excfunction Expected Error class.
causeobject Cause to match.
funcfunction Function to call.
msgstring <optional>
'' Text to complement the failure message.
-
assertRaisesRegExp(exc, regexp, func, msgopt)
-
Asserts the expected exception is raised and the message matches the regular expression.
Parameters:
Name Type Attributes Default Description excfunction Expected Error class.
regexpRegExp Regular expression to match.
funcfunction Function to call.
msgstring <optional>
'' Text to complement the failure message.
-
assertRegExp(target, regexp, msgopt)
-
Asserts the target matches the regular expression.
Parameters:
Name Type Attributes Default Description targetstring Target string to check.
regexpRegExp Regular expression to match.
msgstring <optional>
'' Text to complement the failure message.
-
assertTrue(arg, msgopt)
-
Asserts that the argument is a boolean true.
Parameters:
Name Type Attributes Default Description argobject Argument to test.
msgstring <optional>
'' Text to complement the failure message.
-
doCleanups()
-
Execute all functions registered with addCleanup.
-
equalArray(first, second) → {module:xunit.TestCase~EqualOutput}
-
Parameters:
Name Type Description firstArray.<object> First argument.
secondArray.<object> Second argument.
- Implements:
-
equalEqEqEq(first, second) → {module:xunit.TestCase~EqualOutput}
-
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
- Implements:
-
equalMap(first, second) → {module:xunit.TestCase~EqualOutput}
-
Order is ignored.
Parameters:
Name Type Description firstMap.<object, object> First argument.
secondMap.<object, object> Second argument.
- Implements:
-
equalObject(first, second) → {module:xunit.TestCase~EqualOutput}
-
This currently only tests Object.entries().
Order is ignored.
Other tests, like frozen and sealed states may be implemented later.
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
- Implements:
-
equalRegExp(first, second) → {module:xunit.TestCase~EqualOutput}
-
This converts to strings for comparisons as that encodes all flags.
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
- Implements:
-
equalSet(first, second) → {module:xunit.TestCase~EqualOutput}
-
Order is ignored.
Parameters:
Name Type Description firstSet.<object> First argument.
secondSet.<object> Second argument.
- Implements:
-
equalString(first, second) → {module:xunit.TestCase~EqualOutput}
-
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
- Implements:
-
equalValueOf(first, second) → {module:xunit.TestCase~EqualOutput}
-
For those cases when '===' is too strict.
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
- Implements:
-
fail(msgopt)
-
Immediately fail a test method.
Parameters:
Name Type Attributes Default Description msgstring <optional>
'' Reason for the failure.
Throws:
-
getEqualFunc(first, second) → {module:xunit.TestCase~EqualFunc}
-
Find an equality function appropriate for the arguments.
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
-
repr(item) → {string}
-
Parameters:
Name Type Description itemobject Anything.
Returns:
string -String version of item.
- Deprecated:
- Migrate to this.typeTool.repr().
-
run(resultopt) → {module:xunit~TestResult}
-
Execute the test method registered upon instantiation.
Parameters:
Name Type Attributes Description resultmodule:xunit~TestResult <optional>
Instance for accumulating results. Typically, a test runner will pass in one of these to gather results across multiple tests.
-
setUp()
-
Called once before each test method.
-
skip(msgopt)
-
Immediately skips a test method.
Parameters:
Name Type Attributes Default Description msgstring <optional>
'' Reason for skipping.
Throws:
-
static addClassCleanup(func, …rest)
-
Register a function with arguments to run after all tests in the class have ran.
Parameters:
Name Type Attributes Description funcfunction Function to call.
restobject <repeatable>
Arbitrary arguments to func.
-
static doClassCleanups()
-
Execute all functions registered with addClassCleanup.
-
static register()
-
Register this class with the default test runner infrastructure.
-
static setUpClass()
-
Called once before any instances are created.
Type Definitions
-
EqualFunc(first, second) → {module:xunit.TestCase~EqualOutput}
-
Parameters:
Name Type Description firstobject First argument.
secondobject Second argument.
-
EqualOutput
-
Properties:
Name Type Description equalboolean Result of equality test.
detailstring Details appropriate to the test (e.g., where items differed).