{ } qjs-modules

testharness

Source: lib/testharness.js (pure JS)

A port of the W3C testharness.js (web-platform-tests) framework: define tests, make assertions, and collect results. See also testharnessreport for output.

> Large module; functions grouped by role below.

Defining & running tests

FunctionArgsDescription
test(func, name, properties)1–3Defines a synchronous test.
async_test(func, name, properties)1–3Defines an async test (manual done).
promise_test(func, name, properties)1–3Defines a promise-returning test.
generate_tests(func, args, properties)2–3Generates many tests from argument tuples.
setup(func_or_properties, maybe_properties)1–2Configures the harness before tests run.
promise_setup(func, properties)1–2Async setup.
done()0Signals that all tests are defined/finished.
timeout()0Forces the harness timeout.
step_timeout(func, timeout)2Schedules a callback as a test step.
on_event(object, event, callback)3Adds an event listener (harness helper).

Promise rejection assertions

promise_rejects_js(test, constructor, promise, description), promise_rejects_dom(test, type, promiseOr, …), promise_rejects_exactly(test, exception, promise, description).

Assertions

Truthiness / equality: assert_true, assert_false, assert_equals, assert_not_equals, assert_in_array, assert_object_equals, assert_array_equals, assert_array_approx_equals, assert_approx_equals.

Ordering: assert_less_than, assert_greater_than, assert_less_than_equal, assert_greater_than_equal, assert_between_exclusive, assert_between_inclusive.

Strings / classes: assert_regexp_match, assert_class_string.

Properties: assert_own_property, assert_not_own_property, assert_inherits, assert_idl_attribute, assert_readonly.

Throwing: assert_throws_js, assert_throws_dom, assert_throws_exactly.

Control / combinators: assert_unreached, assert_any, assert_implements, assert_implements_optional.

Result callbacks

add_start_callback, add_test_state_callback, add_result_callback, add_completion_callback.

Cross-context test collection

fetch_tests_from_worker(port), fetch_tests_from_window(window), fetch_tests_from_shadow_realm(realm), begin_shadow_realm_tests(postMessage).

Test environments

WindowTestEnvironment, WorkerTestEnvironment, SharedWorkerTestEnvironment, ServiceWorkerTestEnvironment, ShadowRealmTestEnvironment, ShellTestEnvironment.

Core types & helpers

ExportDescription
Test, RemoteTest, RemoteContextTest object and remote-test plumbing.
Tests, TestsStatus, AssertRecordTest registry, overall status, recorded assertions.
OutputResult formatter/sink.
EventWatcher(test, node, eventTypes, timeoutPromise)Awaits a sequence of events.
format_value(val, seen)Renders a value for messages.
AssertionError(message)Assertion failure error.
OptionalFeatureUnsupportedError(message)Skipped-feature error.
testsThe live test list (let).