Assert class - provide the testing methods.
This class implements a set of comparison / testing methods, that raise TestFailedException
exception if condition is not met.
That unique exception is than caught by the test suite to mark the test as a failure.
Class to store the test results of a single test suite.
Represent a test suite.
The main tests engine class.
Assert class - provide the testing methods.
This class implements a set of comparison / testing methods, that raise TestFailedException
exception if condition is not met.
That unique exception is than caught by the test suite to mark the test as a failure.
Kind: global class
Perform strict equals comparison. Handle all basic types (numbers, boolean, undefined, dates, array, dictionary, etc.) and perform recursive checks. If objects implement ‘equals’ method, will use it.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value. |
expected | \* |
Expected value. |
reason | String |
Optional error reason. |
Perform strict not-equals comparison. Handle all basic types (numbers, boolean, undefined, dates, array, dictionary, etc.) and perform recursive checks. If objects implement ‘equals’ method, will use it.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value. |
expected | \* |
Expected value. |
reason | String |
Optional error reason. |
Perform a simple loose equals using the == operator.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value. |
expected | \* |
Expected value. |
reason | String |
Optional error reason. |
Perform a simple loose equals using the == operator.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value. |
expected | \* |
Expected value. |
reason | String |
Optional error reason. |
Fail the test without condition.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
reason | String |
Optional error reason. |
Make sure given value translates to Boolean true.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
reason | String |
Optional error reason. |
Make sure given value translates to Boolean false.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
reason | String |
Optional error reason. |
Check if values are the same using Object.is().
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
expected | \* |
Expected value. |
reason | String |
Optional error reason. |
Check if values are not the same using !Object.is().
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
expected | \* |
Expected value. |
reason | String |
Optional error reason. |
Call a given method and expect a given exception (or any if ‘errorType’ is not defined).
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
method | \* |
Method to call and expect exception from. |
errorType | \* |
Optional error type to except (if not defined, will except any). |
reason | String |
Optional error reason. |
Check if a value is not null / undefined, but is empty. Can handle any object that has ‘length’ or ‘size’, or return a valid value from Object.keys() or Object.entries().
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
reason | String |
Optional error reason. |
Check if a value is not null / undefined, and is not empty. Can handle any object that has ‘length’ or ‘size’, or return a valid value from Object.keys() or Object.entries().
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
reason | String |
Optional error reason. |
Check if value is an instance of type.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
actual | \* |
Actual value to check. |
type | \* |
Object to check if value is instance of. |
reason | String |
Optional error reason. |
Create a promise and resolve it after given time, used to create sleeping time in test cases.
Kind: instance method of Assert
Param | Type | Description |
---|---|---|
timeMs | Number |
Time to sleep, in ms. |
comment | String |
Optional waiting comment. |
Example
await assert.sleep(1000, 'Wait for one second.');
Class to store the test results of a single test suite.
Kind: global class
Create test results container.
Param | Type | Description |
---|---|---|
suite | TestSuite |
Test suite we create results for. |
logger | \* |
Logger handler class. |
Get test suite name.
Kind: instance property of TestResult
Get test suite description.
Kind: instance property of TestResult
Get test results.
Kind: instance property of TestResult
Get errors count.
Kind: instance property of TestResult
Get success count.
Kind: instance property of TestResult
Get total results count.
Kind: instance property of TestResult
Check if a given test case have results or if its still waiting.
Kind: instance method of TestResult
Returns: True if have any result for test, false otherwise.
Param | Type | Description |
---|---|---|
name | String |
Test case name to check. |
Check if a given test case has an error.
Kind: instance method of TestResult
Returns: True if have an error, false otherwise.
Param | Type | Description |
---|---|---|
name | String |
Test case name to check. |
Check if a given test case is a success.
Kind: instance method of TestResult
Returns: True if done and have no errors, false otherwise.
Param | Type | Description |
---|---|---|
name | String |
Test case name to check. |
Represent a test suite.
Kind: global class
Create the test suite.
Param | Type | Description |
---|---|---|
name | String |
Test suite name. |
params | \* |
Optional additional params. May include: - description: test suite textual description. |
logger | \* |
Logger handler class. |
Get suite name.
Kind: instance property of TestSuite
Get test suite description.
Kind: instance property of TestSuite
Define a test case.
Kind: instance method of TestSuite
Param | Type | Description |
---|---|---|
name | String |
Test case name. |
method | function |
Test case implementation method. Get ‘Assert’ instance as a single parameter. |
params | \* |
Optional additional params for this test case. May include: - timeout: timeout in ms to run the case. defaults to 10000. |
Set a setup method to run before tests.
Kind: instance method of TestSuite
Param | Type | Description |
---|---|---|
method | function |
Setup function to run before tests. |
timeout | Number |
Timeout for setup code, in ms (only for async code). Defaults to 10000. |
Set a setup method to run after tests.
Kind: instance method of TestSuite
Param | Type | Description |
---|---|---|
method | function |
Teardown function to run after tests. |
timeout | Number |
Timeout for teardown code, in ms (only for async code). Defaults to 10000. |
Create an artifical delay between test cases. This will generate a “test case” that just waits for the given time.
Kind: instance method of TestSuite
Param | Type | Description |
---|---|---|
time | Number |
How long to wait, in milliseconds. |
reason | String |
Waiting reason, will appear as case name. |
Promise.<TestResult>
Run this test suite.
Kind: instance method of TestSuite
Returns: Promise.<TestResult>
- Test results.
The main tests engine class.
Kind: global class
TestSuite
Promise.<Object.<String, TestResult>>
Create the tests engine.
Param | Type | Description |
---|---|---|
logger | \* |
Optional object for Testizy logs. If not set, will use console. If set to null, will not output anything. |
Example
// create the tests suite.
let testizy = new Testizy();
// define a test suite for arithmetic operators.
testizy.suite('Arithmetics', (suite) => {
suite.case('1 + 1 = 2', (assert) => {
assert.equals(1 + 1, 2);
});
});
// run all tests and render them
testizy.run(null, testizy.renderTest);
TestSuite
Create a new test suite.
Kind: instance method of Testizy
Returns: TestSuite
- Newly created test suite.
Param | Type | Description |
---|---|---|
name | String |
Test suite name. |
generator | function |
Function to define the test suite cases. Receive a single parameter of ‘TestSuit’ type. |
params | \* |
Optional additional params. |
Promise.<Object.<String, TestResult>>
Run tests.
Kind: instance method of Testizy
Returns: Promise.<Object.<String, TestResult>>
- Map with test suite name as key, and test results as value.
Param | Type | Description |
---|---|---|
tests | String | Array.<String> |
Optional test suite or list of test suite names to run. Omit to run everything. |
onTestFinish | function |
Optional method to call with (testName, result) every time a test suite finish running. |
Inject default CSS rules for testizy classes.
Kind: instance method of Testizy
Render test results as HTML elements.
Kind: instance method of Testizy
Param | Type | Description |
---|---|---|
results | Object.<String, TestResult> |
Test results to render. |
parentDom | Element |
Optional parent DOM element to render in (will use document.body if not set). |
Render a single test results as HTML elements.
Kind: instance method of Testizy
Param | Type | Description |
---|---|---|
suiteName | String |
test suite name. |
results | suiteResults |
Test results to render. |
parentDom | Element |
Optional parent DOM element to render in (will use document.body if not set). |
Write all test results to log or console.
Kind: instance method of Testizy
Param | Type | Description |
---|---|---|
results | Object.<String, TestResult> |
Test results to log. |
colors | Boolean |
Should we use console colors? Defaults to true. |
_console | \* |
Console instance to use. Defaults to console. |
Write a single test result to log or console.
Kind: instance method of Testizy
Param | Type | Description |
---|---|---|
suiteName | String |
Test suite name. |
suiteResults | TestResult |
Test result to log. |
colors | Boolean |
Should we use console colors? Defaults to true. |
_console | \* |
Console instance to use. Defaults to console. |