Testizy

Classes

Assert

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.

TestResult

Class to store the test results of a single test suite.

TestSuite

Represent a test suite.

Testizy

The main tests engine class.

Assert

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

assert.equals(actual, expected, reason)

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.

assert.notEquals(actual, expected, 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.

assert.looseEquals(actual, expected, 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.

assert.looseNotEquals(actual, expected, 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.

assert.fail(reason)

Fail the test without condition.

Kind: instance method of Assert

Param Type Description
reason String Optional error reason.

assert.true(actual, 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.

assert.false(actual, 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.

assert.is(actual, expected, 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.

assert.isNot(actual, expected, 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.

assert.except(method, errorType, 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.

assert.empty(actual, 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.

assert.notEmpty(actual, 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.

assert.instanceOf(actual, type, 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.

assert.wait(timeMs, comment)

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.');

TestResult

Class to store the test results of a single test suite.

Kind: global class

new TestResult(suite, logger)

Create test results container.

Param Type Description
suite TestSuite Test suite we create results for.
logger \* Logger handler class.

testResult.testName

Get test suite name.

Kind: instance property of TestResult

testResult.testDescription

Get test suite description.

Kind: instance property of TestResult

testResult.results

Get test results.

Kind: instance property of TestResult

testResult.errorsCount

Get errors count.

Kind: instance property of TestResult

testResult.successCount

Get success count.

Kind: instance property of TestResult

testResult.totalCount

Get total results count.

Kind: instance property of TestResult

testResult.hasResultFor(name) ⇒

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.

testResult.isError(name) ⇒

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.

testResult.isSuccess(name) ⇒

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.

TestSuite

Represent a test suite.

Kind: global class

new TestSuite(name, params, logger)

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.

testSuite.name

Get suite name.

Kind: instance property of TestSuite

testSuite.description

Get test suite description.

Kind: instance property of TestSuite

testSuite.case(name, method, params)

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.

testSuite.setup(method, timeout)

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.

testSuite.teardown(method, timeout)

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.

testSuite.wait(time, reason)

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.

testSuite.run() ⇒ Promise.<TestResult>

Run this test suite.

Kind: instance method of TestSuite
Returns: Promise.<TestResult> - Test results.

Testizy

The main tests engine class.

Kind: global class

new Testizy(logger)

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);

testizy.suite(name, generator, params) ⇒ 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.

testizy.run(tests, onTestFinish) ⇒ 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.

testizy.injectDefaultCss()

Inject default CSS rules for testizy classes.

Kind: instance method of Testizy

testizy.renderAllTests(results, parentDom)

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).

testizy.renderTest(suiteName, results, parentDom)

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).

testizy.logAllTests(results, colors, _console)

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.

testizy.logTest(suiteName, suiteResults, colors, _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.