Very simple tools for unit testing. These are used by module:hcjeTools/testing/runner to test JavaScript files. The module is used soley by the runner.js script and there is no need to import it or call its methods directly from any test script.
- Source:
Methods
(static) areEqual(result, expected)
Test if result and error are equal. There is normally no need to use this method directly as it is automatically invoked by the runner script by setting an appropriate value for the compare property in the TestDefinition.
Parameters:
| Name | Type | Description |
|---|---|---|
result |
Error | The actual result. |
expected |
Error | The expected result |
- Source:
- See:
-
- module:hcjeTools/testing/utils~compare
Throws:
-
Throws error if the result and expected are not regarded as equal.
- Type
- Error
(static) areEqualToDp(result, expected, decimalPlaces)
Test if result and error are equal to a defined number of decimal places. There is normally no need to use this method directly as it is automatically invoked by the runner script by setting an appropriate value for the compare property in the TestDefinition.
Parameters:
| Name | Type | Description |
|---|---|---|
result |
Error | The actual result. |
expected |
Error | The expected result |
decimalPlaces |
number | The number of decimal places. |
- Source:
- See:
-
- module:hcjeTools/testing/utils~compare
Throws:
-
Throws error if the result and expected are not equal when fixed to the specified number of decimal places.
- Type
- Error
(static) areEquivalent(result, expected)
Test if result and error equivalent. The test is done by stringify both and then comparing. There is normally no need to use this method directly as it is automatically invoked by the runner script by setting an appropriate value for the compare property in the TestDefinition.
Parameters:
| Name | Type | Description |
|---|---|---|
result |
Error | |
expected |
Error |
- Source:
- See:
-
- module:hcjeTools/testing/utils~compare
Throws:
-
Throws error if the result and expected are not regarded as equal.
- Type
- Error
(static) areStrictlyEqual(result, expected)
Test if result and error strictly equal. There is normally no need to use this method directly as it is automatically invoked by the runner script by setting an appropriate value for the compare property in the TestDefinition.
Parameters:
| Name | Type | Description |
|---|---|---|
result |
Error | |
expected |
Error |
- Source:
- See:
-
- module:hcjeTools/testing/utils~compare
Throws:
-
Throws error if the result and expected are not regarded as equal.
- Type
- Error
(static) it(moduleName, definition) → {Promise}
Run a test. There is normally no need to use this method directly as it is automatically invoked by the runner script.
Parameters:
| Name | Type | Description |
|---|---|---|
moduleName |
string | Name of the module under test. |
definition |
module:hcjeTools/testing/runner~TestDefinition | Details of the test. |
- Source:
Returns:
Fulfils to TestResult
- Type
- Promise
(static) match(result, testRegex)
Test if the result matches a regex. There is normally no need to use this method directly as it is automatically invoked by the runner script by setting an appropriate value for the compare property in the TestDefinition.
Parameters:
| Name | Type | Description |
|---|---|---|
result |
* | Result to test. This is coerced to a string. |
testRegex |
RegExp | Test regex |
- Source:
Throws:
-
Error thrown on test failure.
- Type
- Error