diff --git a/_config.yml b/_config.yml
index 826db84..7f87289 100644
--- a/_config.yml
+++ b/_config.yml
@@ -26,7 +26,6 @@ exclude:
- vendor
- build
-
# Theme settings
#
# Amethyst theme options are documented at:
@@ -54,7 +53,6 @@ amethyst:
collection: qunitjs_com
search_only_api_key: Zh8mMgohXECel9wjPwqT7lekLSG3OCgz
-
# Blog archives
#
# Docs: https://github.com/jekyll/jekyll-archives/
diff --git a/_data/projects.yml b/_data/projects.yml
index b050bed..f1c94a3 100644
--- a/_data/projects.yml
+++ b/_data/projects.yml
@@ -224,7 +224,7 @@ projects:
href: https://github.com/videojs/http-streaming
- name: mux.js
href: https://github.com/videojs/mux.js
-
+
- name: Wikibase
href: https://wikiba.se/
sub:
diff --git a/_data/sidebar_api.yml b/_data/sidebar_api.yml
new file mode 100644
index 0000000..13ebd35
--- /dev/null
+++ b/_data/sidebar_api.yml
@@ -0,0 +1,23 @@
+- group: main
+ expand: initial
+
+- group: assert
+
+- group: callbacks
+
+- group: async
+ # These pages are all in at least one other group.
+ # It exists for discoverability, but we don't need
+ # to highlight its pages in two places.
+ expand: false
+
+- title: Configuration
+ group: config
+
+- group: extension
+
+- group: deprecated
+ expand: false
+
+# - group: removed
+# expand: false
diff --git a/_data/sitenav.yml b/_data/sitenav.yml
index aa115d8..7a685f0 100644
--- a/_data/sitenav.yml
+++ b/_data/sitenav.yml
@@ -1,4 +1,5 @@
- name: Guides
+ href: /guides/
sub:
- name: Getting Started
href: /intro/
@@ -9,7 +10,7 @@
- name: 2.x Upgrade Guide
href: /upgrade-guide-2.x/
- name: Documentation
- href: https://api.qunitjs.com/
+ href: /api/
- name: About
href: /about/
sub:
diff --git a/api/QUnit/hooks.md b/api/QUnit/hooks.md
new file mode 100644
index 0000000..3cf11c2
--- /dev/null
+++ b/api/QUnit/hooks.md
@@ -0,0 +1,39 @@
+---
+layout: page-api
+title: QUnit.hooks
+excerpt: Add global callbacks to run before or after each test.
+groups:
+ - extension
+redirect_from:
+ - "/QUnit/hooks/"
+version_added: "2.18.0"
+---
+
+`QUnit.hooks.beforeEach( callback )`
+`QUnit.hooks.afterEach( callback )`
+
+Register a global callback to run before or after each test.
+
+| parameter | description |
+|-----------|-------------|
+| callback (function) | Callback to execute. Called with an [assert](../assert/index.md) argument. |
+
+This is the equivalent of applying a `QUnit.module()` hook to all modules and all tests, including global tests that are not associated with any module.
+
+Similar to module hooks, global hooks support async functions or returning a Promise, which will be waited for before QUnit continues executing tests. Each global hook also has access to the same `assert` object and test context as the [QUnit.test](./test.md) that the hook is running for.
+
+For more details about hooks, refer to [QUnit.module § Hooks](./module.md#hooks).
+
+## Examples
+
+```js
+QUnit.hooks.beforeEach(function () {
+ this.app = new MyApp();
+});
+
+QUnit.hooks.afterEach(async function (assert) {
+ assert.deepEqual([], await this.app.getErrors(), 'MyApp errors');
+
+ MyApp.reset();
+});
+```
diff --git a/api/QUnit/index.md b/api/QUnit/index.md
new file mode 100644
index 0000000..b351055
--- /dev/null
+++ b/api/QUnit/index.md
@@ -0,0 +1,7 @@
+---
+layout: group
+group: main
+title: Main methods
+redirect_from:
+ - "/QUnit/"
+---
diff --git a/api/QUnit/load.md b/api/QUnit/load.md
new file mode 100644
index 0000000..07f1fa6
--- /dev/null
+++ b/api/QUnit/load.md
@@ -0,0 +1,50 @@
+---
+layout: page-api
+title: QUnit.load()
+excerpt: Inform the test runner that code has finished loading.
+groups:
+ - deprecated
+redirect_from:
+ - "/QUnit/load/"
+version_added: "1.0.0"
+version_deprecated: "unreleased"
+---
+
+`QUnit.load()`
+
+Inform the test runner that your source code and tests have finished loading.
+
+This method was used in conjunction with the [`QUnit.config.autostart`](../config/autostart.md) option in a web browser, to indicate when your custom way of loading scripts is complete.
+
+As of [QUnit 2.1.1](https://github.com/qunitjs/qunit/releases/tag/2.1.1), calls to `QUnit.load()` are no longer needed. Existing calls are usually ignored and safe to remove.
+
+
This method is __deprecated__. Remove call, or replace by a single call to [`QUnit.start()`](./start.md).
+ +## Changelog + +| UNRELEASED | Deprecated. Use [`QUnit.start()`](./start.md) instead. +| [QUnit 2.1.1](https://github.com/qunitjs/qunit/releases/tag/2.1.1) | `QUnit.start()` no longer requires calling `QUnit.load()` first. + +## Migration guide + +If you still call `QUnit.load()` with QUnit 2.2 or later, the call is usually redundant and safe to remove. + +### If you call both `QUnit.load()` and `QUnit.start()` + +If your project started with QUnit 1.x, and you use `QUnit.config.autostart = false`, then you might be calling both of these methods. In the QUnit 1.x era, [`QUnit.start()`](./start.md) required that you also call `QUnit.load()` first. + +This is no longer needed since [QUnit 2.1.1](https://github.com/qunitjs/qunit/releases/tag/2.1.1), and the call to `QUnit.load()` is safe to remove. + +### If you call `QUnit.load()` + +Prior to QUnit 2.21, the built-in HTML Reporter called `QUnit.load()` from the window.onload event, which in turn gracefully calls `QUnit.start()` if it has not been called already. + +If your test runner works in a similar way, call [`QUnit.start()`](./start.md) instead of `QUnit.load()`. This will solve the deprecation warning and prepares you for QUnit 3. + +### Karma runner + +``` +QUnit.load is deprecated and will be removed in QUnit 3.0. +``` + +If you encounter this warning in Karma output, upgrade to [karma-qunit](https://github.com/karma-runner/karma-qunit) 4.2.0 or later, which [fixes](https://github.com/karma-runner/karma-qunit/pull/184) this warning. diff --git a/api/QUnit/module.md b/api/QUnit/module.md new file mode 100644 index 0000000..66e5e1a --- /dev/null +++ b/api/QUnit/module.md @@ -0,0 +1,438 @@ +--- +layout: page-api +title: QUnit.module() +excerpt: Group related tests under a common label. +groups: + - main +redirect_from: + - "/QUnit.module/" + - "/QUnit/module/" + - "/module/" +version_added: "1.0.0" +--- + +`QUnit.module( name )`It is discouraged to dynamically create a new [QUnit.test](./test.md) from within a hook. In order to satisfy the requirement for the `after` hook to only run once and to be the last hook in a module, QUnit may associate dynamically defined tests with the parent module instead, or as global test. It is recommended to define any dynamic tests via [`QUnit.begin()`](../callbacks/QUnit.begin.md).
+ +### Options object + +You can use the options object to add [hooks](#hooks). + +| name | description | +|-----------|-------------| +| `before` (function) | Runs before the first test. | +| `beforeEach` (function) | Runs before each test. | +| `afterEach` (function) | Runs after each test. | +| `after` (function) | Runs after the last test. | + +Properties on the module options object are copied over to the test context object at the start of each test. Such properties can also be changed from the hook callbacks. See [§ Using the test context](#using-the-test-context). + +Example: [§ Declaring module options](#declaring-module-options). + +### Nested scope + +Modules can be nested to group tests under a common label within a parent module. + +The module scope is given a `hooks` object which can be used to procedurally add [hooks](#hooks). + +| parameter | description | +|-----------|-------------| +| `hooks` (object) | An object for adding hooks. | + +Example: [§ Nested module scope](#nested-module-scope). + +## Changelog + +| [QUnit 2.4](https://github.com/qunitjs/qunit/releases/tag/2.4.0) | The `QUnit.module.only()`, `QUnit.module.skip()`, and `QUnit.module.todo()` aliases were introduced. +| [QUnit 2.0](https://github.com/qunitjs/qunit/releases/tag/2.0.0) | The `before` and `after` options were introduced. +| [QUnit 1.20](https://github.com/qunitjs/qunit/releases/tag/1.20.0) | The `nested` scope feature was introduced. +| [QUnit 1.16](https://github.com/qunitjs/qunit/releases/tag/1.16.0) | The `beforeEach` and `afterEach` options were introduced.Prior to QUnit 1.16, this method was used for resuming an async `QUnit.test()` function, as complement to `QUnit.stop()`. To resume asynchronous tests, use [`assert.async()`](../assert/async.md) instead.
+ +## Changelog + +| [QUnit 2.1.1](https://github.com/qunitjs/qunit/releases/tag/2.1.1) | `QUnit.start()` no longer requires calling [`QUnit.load()`](./load.md) first. +| [QUnit 2.0](https://github.com/qunitjs/qunit/releases/tag/2.0.0) | Support for calling `start()` to resume an async test was removed. ([Migration guide](../../upgrade-guide-2.x.md#introducing-assertasync)) +| [QUnit 1.16](https://github.com/qunitjs/qunit/releases/tag/1.16.0) | Use of `start()` to resume an async test was deprecated in favour of [`assert.async()`](../assert/async.md). diff --git a/api/QUnit/test.each.md b/api/QUnit/test.each.md new file mode 100644 index 0000000..0782192 --- /dev/null +++ b/api/QUnit/test.each.md @@ -0,0 +1,115 @@ +--- +layout: page-api +title: QUnit.test.each() +excerpt: Add tests using a data provider. +groups: + - main +redirect_from: + - "/QUnit/test.each/" +version_added: "2.16.0" +--- + +`QUnit.test.each( name, dataset, callback )`In very few environments, like Closure Compiler, `throws` may cause an error. There you can use `assert.raises()`. It has the same signature and behaviour, just a different name.
+ +## Changelog + +| [QUnit 2.12](https://github.com/qunitjs/qunit/releases/tag/2.12.0) | Added support for arrow functions as `expectedMatcher` callback function. +| [QUnit 1.9](https://github.com/qunitjs/qunit/releases/tag/v1.9.0) | `assert.raises()` was renamed to `assert.throws()`.type | +`boolean` | +
---|---|
default | +`true` | +
type | +`boolean` | +
---|---|
default | +`true` | +
type | +`boolean` | +
---|---|
default | +`true` | +
type | +`object` (read-only) | +
---|
type | +`boolean` | +
---|---|
default | +`true` | +
type | +`string` or `undefined` | +
---|---|
default | +`undefined` | +
+ +This option is available as [CLI option](../../cli.md), as control in the [HTML Reporter](../../intro.md#in-the-browser), and supported as URL query parameter. + +
+ +QUnit only runs tests of which the module name or test name are a case-insensitive substring match for the filter string. You can invert the filter by prefixing an exclamation mark (`!`) to the string, in which case we skip the matched tests, and run the tests that don't match the filter. + +You can also match via a regular expression by setting the filter to a regular expression literal, enclosed by slashes, such as `/(this|that)/`. + +While substring filters are always **case-insensitive**, a regular expression is case-sensitive by default. + +See also: +* [QUnit.config.module](./module.md) + +## Examples + +### Substring filter + +The below matches `FooBar` and `foo > bar`, because string matching is case-insensitive. + +```js +QUnit.config.filter = 'foo'; +``` + +As inversed filter, the below skips `FooBar` and `foo > bar`, but runs `Bar` and `bar > sub`. + +```js +QUnit.config.filter = '!foo'; +``` + +### Regular expression filter + +The below matches `foo` but not `Foo`, because regexes are case-sensitive by default. + +```js +QUnit.config.filter = '/foo/'; +``` + +The below matches both `foo` and `Foo`. + +```js +QUnit.config.filter = '/foo/i'; +``` + +The below skips both `foo` and `Foo`. + +```js +QUnit.config.filter = '!/foo/i'; +``` + +The below matches `foo`, `foo > sub`, and `foo.sub`, but skips `bar`, `bar.foo`, and `FooBar`. + +```js +QUnit.config.filter = '/^foo/'; +``` diff --git a/api/config/fixture.md b/api/config/fixture.md new file mode 100644 index 0000000..b1cf7f3 --- /dev/null +++ b/api/config/fixture.md @@ -0,0 +1,27 @@ +--- +layout: page-api +title: QUnit.config.fixture +excerpt: HTML content to render in the fixture container at the start of each test (HTML Reporter). +groups: + - config +redirect_from: + - "/config/fixture/" +version_added: "1.0.0" +--- + +In the HTML Reporter, this HTML content will be rendered in the fixture container at the start of each test. + +type | +`string` or `null` or `undefined` | +
---|---|
default | +`undefined` | +
type | +`boolean` | +
---|---|
default | +`false` | +
This option can also be controlled via the [HTML Reporter](../../intro.md#in-the-browser).
+ +By default, the HTML Reporter will list (in collapsed form) the names of all passed tests. Enable this option, to only list failing tests. diff --git a/api/config/index.md b/api/config/index.md new file mode 100644 index 0000000..137e9ed --- /dev/null +++ b/api/config/index.md @@ -0,0 +1,40 @@ +--- +layout: group +group: config +title: QUnit.config +redirect_from: + - "/QUnit.config/" + - "/config/" +--- + +General configuration options for QUnit. + +## Preconfiguring QUnit + +If you load QUnit asynchronously or otherwise need to configure QUnit before it is loaded, you can predefine the configuration by creating a global variable `QUnit` with a `config` property. + +The config values specified here will be carried over to the real `QUnit.config` object. Any other properties of this object will be ignored. + +```js +// Implicit global +// Supported everywhere, including old browsers. (But not ES strict mode.) +QUnit = { + config: { + autostart: false, + maxDepth: 12 + } +}; + +// Browser global +// For all browsers (including strict mode and old browsers) +window.QUnit = { /* .. */ }; + +// Isomorphic global +// For modern browsers, SpiderMonkey, and Node.js (incl. strict mode). +globalThis.QUnit = { /* .. */ }; +``` + +### Changelog + +| [QUnit 2.18.1](https://github.com/qunitjs/qunit/releases/tag/2.18.1) | Preconfig support added for SpiderMonkey and other environments.type | +`number` | +
---|---|
default | +`5` | +
type | +`string` or `undefined` | +
---|---|
default | +`undefined` | +
This option can also be set by URL query parameter.
+ +When specified, only a single module will be run if its name is a complete case-insensitive match. If no module name matches, then no tests will be run. + +This option is undefined by default, which means all loaded test modules will be run. + +See also: +* [QUnit.config.filter](./filter.md) +* [QUnit.config.moduleId](./moduleId.md) + +## Changelog + +| [QUnit 1.23](https://github.com/qunitjs/qunit/releases/tag/1.23.0) | The public config property was restored. +| [QUnit 1.16](https://github.com/qunitjs/qunit/releases/tag/1.16.0) | The public config property was removed (the URL query parameter was unaffected). diff --git a/api/config/moduleId.md b/api/config/moduleId.md new file mode 100644 index 0000000..bcabfb5 --- /dev/null +++ b/api/config/moduleId.md @@ -0,0 +1,31 @@ +--- +layout: page-api +title: QUnit.config.moduleId +excerpt: Select one or more modules to run, by their internal ID (HTML Reporter). +groups: + - config +redirect_from: + - "/config/moduleId/" +version_added: "1.23.0" +--- + +In the HTML Reporter, select one or more modules to run by their internal ID. + +type | +`array` or `undefined` | +
---|---|
default | +`undefined` | +
This option can be controlled via the [HTML Reporter](../../intro.md#in-the-browser) interface.
+ +Specify modules by their internally hashed identifier for a given module. You can specify one or multiple modules to run. This option powers the multi-select dropdown menu in the HTML Reporter. + +See also: +* [QUnit.config.module](./module.md) +* [QUnit.config.testId](./testId.md) diff --git a/api/config/modules.md b/api/config/modules.md new file mode 100644 index 0000000..2989f12 --- /dev/null +++ b/api/config/modules.md @@ -0,0 +1,41 @@ +--- +layout: page-api +title: QUnit.config.modules +excerpt: List of defined test modules. +groups: + - config + - extension +redirect_from: + - "/config/modules/" +version_added: "1.16.0" +--- + +List of defined test modules. + +type | +`Array |
+
---|
type | +`boolean` | +
---|---|
default | +`false` | +
This option can also be controlled via the [HTML Reporter](../../intro.md#in-the-browser).
diff --git a/api/config/notrycatch.md b/api/config/notrycatch.md new file mode 100644 index 0000000..d4e9a65 --- /dev/null +++ b/api/config/notrycatch.md @@ -0,0 +1,29 @@ +--- +layout: page-api +title: QUnit.config.notrycatch +excerpt: Disable handling of uncaught exceptions during tests. +groups: + - config +redirect_from: + - "/config/notrycatch/" +version_added: "1.0.0" +--- + +Disable handling of uncaught exceptions during tests. + +type | +`boolean` | +
---|---|
default | +`false` | +
This option can also be controlled via the [HTML Reporter](../../intro.md#in-the-browser) interface, and is supported as URL query parameter.
+ +By default, QUnit handles uncaught exceptions during test execution and reports them as test failures. This lets other tests continue running and allows reporters to summarise results. + +Enabling this flag will disable this error handling, allowing you to more easily debug uncaught exceptions through developer tools. diff --git a/api/config/reorder.md b/api/config/reorder.md new file mode 100644 index 0000000..9526b35 --- /dev/null +++ b/api/config/reorder.md @@ -0,0 +1,29 @@ +--- +layout: page-api +title: QUnit.config.reorder +excerpt: Allow re-running of previously failed tests out of order. +groups: + - config +redirect_from: + - "/config/reorder/" +version_added: "1.0.0" +--- + +Allow re-running of previously failed tests out of order, before all other tests. + +type | +`boolean` | +
---|---|
default | +`true` | +
type | +`boolean` | +
---|---|
default | +`false` | +
type | +`boolean` | +
---|---|
default | +`true` | +
type | +`string` or `boolean` or `undefined` | +
---|---|
default | +`undefined` | +
This option is also available as [CLI option](../../cli.md), and as URL query parameter in the browser.
+ +When set to boolean true, or a string, QUnit will run tests in a [seeded-random order](https://en.wikipedia.org/wiki/Random_seed). + +The provided string will be used as the seed in a pseudo-random number generator to ensure that results are reproducible. The randomization will also respect the [reorder](./reorder.md) option if enabled and re-run failed tests first without randomizing them. + +Randomly ordering your tests can help identify non-atomic tests which either depend on a previous test or are leaking state to subsequent tests. + +If `seed` is boolean true (or set as URL query parameter without a value), then QUnit will generate on-demand a new random value to use as seed. You can then read the seed at runtime from the configuration value, and use it to reproduce the same test sequence later. diff --git a/api/config/storage.md b/api/config/storage.md new file mode 100644 index 0000000..e5a4dae --- /dev/null +++ b/api/config/storage.md @@ -0,0 +1,27 @@ +--- +layout: page-api +title: QUnit.config.storage +excerpt: The Storage object to use for remembering failed tests between runs. +groups: + - config +redirect_from: + - "/config/storage/" +version_added: "2.1.0" +--- + +The Storage object to use for remembering failed tests between runs. + +type | +`object` or `undefined` | +
---|---|
default | +`globalThis.sessionStorage` | +
type | +`array` or `undefined` | +
---|---|
default | +`undefined` | +
This option can be controlled via the [HTML Reporter](../../intro.md#in-the-browser) interface.
+ +This property allows QUnit to run specific tests by their internally hashed identifier. You can specify one or multiple tests to run. This option powers the "Rerun" button in the HTML Reporter. + +See also: +* [QUnit.config.filter](./filter.md) +* [QUnit.config.moduleId](./moduleId.md) diff --git a/api/config/testTimeout.md b/api/config/testTimeout.md new file mode 100644 index 0000000..1ed2534 --- /dev/null +++ b/api/config/testTimeout.md @@ -0,0 +1,25 @@ +--- +layout: page-api +title: QUnit.config.testTimeout +excerpt: Set a global default timeout after which a test will fail. +groups: + - config +redirect_from: + - "/config/testTimeout/" +version_added: "1.0.0" +--- + +Set a global default timeout in milliseconds after which a test will fail. This helps to detect async tests that are broken, and prevents tests from running indefinitely. + +type | +`number` or `undefined` | +
---|---|
default | +`undefined` | +
type | +`array` | +
---|---|
default | +`[]` | +
This method is __deprecated__ and it's recommended to use [`Object.assign()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) instead.
+ +| name | description | +|------|-------------| +| `target` | An object whose properties are to be modified | +| `mixin` | An object describing which properties should be modified | + +This method will modify the `target` object to contain the "own" properties defined by the `mixin`. If the `mixin` object specifies the value of any attribute as `undefined`, this property will instead be removed from the `target` object. + +## Examples + +Use `QUnit.extend` to merge two objects. + +```js +QUnit.test('QUnit.extend', assert => { + const base = { + a: 1, + b: 2, + z: 3 + }; + QUnit.extend(base, { + b: 2.5, + c: 3, + z: undefined + }); + + assert.strictEqual(base.a, 1, 'Unspecified values are not modified'); + assert.strictEqual(base.b, 2.5, 'Existing values are updated'); + assert.strictEqual(base.c, 3, 'New values are defined'); + assert.false('z' in base, 'Values specified as `undefined` are removed'); +}); +``` diff --git a/api/extension/QUnit.onUncaughtException.md b/api/extension/QUnit.onUncaughtException.md new file mode 100644 index 0000000..0bbe505 --- /dev/null +++ b/api/extension/QUnit.onUncaughtException.md @@ -0,0 +1,36 @@ +--- +layout: page-api +title: QUnit.onUncaughtException() +excerpt: Handle a global error. +groups: + - extension +version_added: "2.17.0" +redirect_from: + - "/config/QUnit.onUncaughtException/" + - "/extension/QUnit.onUncaughtException/" +--- + +`QUnit.onUncaughtException( error )` + +Handle a global error that should result in a failed test run. + +| name | description | +|------|-------------| +| `error` (any) | Usually an `Error` object, but any other thrown or rejected value may be given as well. | + +## Examples + +```js +const error = new Error('Failed to reverse the polarity of the neutron flow'); +QUnit.onUncaughtException(error); +``` + +```js +process.on('uncaughtException', QUnit.onUncaughtException); +``` + +```js +window.addEventListener('unhandledrejection', function (event) { + QUnit.onUncaughtException(event.reason); +}); +``` diff --git a/api/extension/QUnit.push.md b/api/extension/QUnit.push.md new file mode 100644 index 0000000..eb24991 --- /dev/null +++ b/api/extension/QUnit.push.md @@ -0,0 +1,30 @@ +--- +layout: page-api +title: QUnit.push() +excerpt: Report the result of a custom assertion. +groups: + - extension + - deprecated +redirect_from: + - "/config/QUnit.push/" + - "/extension/QUnit.push/" +version_added: "1.0.0" +version_deprecated: "2.1.0" +--- + +`QUnit.push( result, actual, expected, message )` + +Report the result of a custom assertion. + +This method is __deprecated__ and it's recommended to use [`pushResult`](../assert/pushResult.md) in the assertion context instead.
+ +| name | description | +|------|-------------| +| `result` (boolean) | Result of the assertion | +| `actual` | Expression being tested | +| `expected` | Known comparison value | +| `message` (string) | A short description of the assertion | + +`QUnit.push` reflects to the current running test, and it may leak assertions in asynchronous mode. Checkout [`assert.pushResult()`](../assert/pushResult.md) to set a proper custom assertion. + +Invoking `QUnit.push` allows to create a readable expectation that is not defined by any of QUnit's built-in assertions. diff --git a/api/extension/QUnit.stack.md b/api/extension/QUnit.stack.md new file mode 100644 index 0000000..4eb094c --- /dev/null +++ b/api/extension/QUnit.stack.md @@ -0,0 +1,45 @@ +--- +layout: page-api +title: QUnit.stack() +excerpt: Return a single line string representing the stacktrace. +groups: + - extension +redirect_from: + - "/config/QUnit.stack/" + - "/extension/QUnit.stack/" +version_added: "1.19.0" +--- + +`QUnit.stack( offset = 0 )` + +Return a single line string representing the stacktrace (call stack). + +| name | description | +|------|-------------| +| `offset` (number) | Set the stacktrace line offset. Defaults to `0` | + +This method returns a single line string representing the stacktrace from where it was called. According to its offset argument, `QUnit.stack()` will return the correspondent line from the call stack. + +The default offset is 0 and will return the current location where it was called. + +Not all [browsers support retrieving stracktraces][browsers]. In those, `QUnit.stack()` will return `undefined`. + +[browsers]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/Stack#Browser_compatibility + +## Examples + +The stacktrace line can be used on custom assertions and reporters. The following example [logs](../callbacks/QUnit.log.md) the line of each passing assertion. + +```js +QUnit.log(function (details) { + if (details.result) { + // 5 is the line reference for the assertion method, not the following line. + console.log(QUnit.stack(5)); + } +}); + +QUnit.test('foo', assert => { + // the log callback will report the position of the following line. + assert.true(true); +}); +``` diff --git a/api/extension/index.md b/api/extension/index.md new file mode 100644 index 0000000..c5d63cf --- /dev/null +++ b/api/extension/index.md @@ -0,0 +1,7 @@ +--- +layout: group +group: extension +title: Extension interface +redirect_from: + - "/extension/" +--- diff --git a/api/index.md b/api/index.md new file mode 100644 index 0000000..fb7a91f --- /dev/null +++ b/api/index.md @@ -0,0 +1,21 @@ +--- +layout: page-api +title: QUnit API +excerpt: API reference documentation for QUnit. +amethyst: + prepend_description_heading: false +redirect_from: + - "/category/all/" +--- + +If you're new to QUnit, check out [Getting Started](../intro.md)! + +QUnit is a powerful, easy-to-use JavaScript unit test suite. QUnit has no dependencies and supports Node.js, SpiderMonkey, and all [major browsers](../intro.md#browser-support). + + + +* [Main methods](./QUnit/) +* [Assertions](./assert/) +* [Callback events](./callbacks/) +* [Configuration options](./config/) +* [Extension interface](./extension/) diff --git a/api/removed.md b/api/removed.md new file mode 100644 index 0000000..9dafa67 --- /dev/null +++ b/api/removed.md @@ -0,0 +1,7 @@ +--- +layout: group +group: removed +title: Removed methods +redirect_from: + - "/removed/" +--- diff --git a/brand.md b/brand.md index 49adde1..8717253 100644 --- a/brand.md +++ b/brand.md @@ -11,19 +11,23 @@ amethyst: * QUnit Secondary Purple `#390F39`
+
**QUnit Primary Purple**
HEX: #9C3493
CMYK: 0 67 6 39
RGB: 156 52 147
Pantone: 253
+
+
**QUnit Secondary Purple**
HEX: #390F39
CMYK: 0 74 0 78
RGB: 57 15 57
Pantone: 229
+
How to use the QUnit CLI (command-line interface), after [installing it from npm](./intro.md#in-nodejs).
++ +How to use the QUnit CLI (command-line interface), after [installing it from npm](./intro.md#in-nodejs). + +
## QUnit CLI options @@ -34,7 +38,7 @@ Only run tests that match the given filter. The filter is matched against the mo Examples: `--filter foo`, `--filter !foo`, `--filter "/foo/"`, `--filter "!/foo/"` -Check [`QUnit.config.filter`](https://api.qunitjs.com/config/filter/) for more information. +Check [`QUnit.config.filter`](./api/config/filter.md) for more information. ### `--module` @@ -42,7 +46,7 @@ Only run tests that belong to the specified module. The name is matched case-ins Examples: `--module foo`, `--module "Foo"` -Check [`QUnit.config.module`](https://api.qunitjs.com/config/module/) for more information. +Check [`QUnit.config.module`](./api/config/module.md) for more information. ### `--reporter` @@ -53,7 +57,7 @@ Run `qunit --reporterTests can be run anywhere; Node, your browser, even inside a Web Worker. Test your code where it runs.
+QUnit can run anywhere; web browsers, Node, SpiderMonkey, even in a Web Worker! Test your code where it runs.
The following guide will get you up-and-running with QUnit either in Node.js or [in the Browser](#in-the-browser).
++ +The following guide will get you up-and-running with QUnit either in Node.js or [in the Browser](#in-the-browser). + +
+ +QUnit has no dependencies and supports Node.js, SpiderMonkey, and all [major browsers](#browser-support). ## In Node.js @@ -43,7 +49,7 @@ QUnit.test('two numbers', assert => { }); ``` -This defines a test suite for the "add" feature, with a single test case that verifies the result of adding two numbers together. Refer to the [`QUnit.test()` page](https://api.qunitjs.com/QUnit/test/) in our API Documentation for how to organise tests and make other assertions. +This defines a test suite for the "add" feature, with a single test case that verifies the result of adding two numbers together. Refer to the [`QUnit.test()` page](./api/QUnit/test.md) in our API Documentation for how to organise tests and make other assertions. You can now run your first test through the [QUnit CLI](./cli.md). It is recommended that you run the `qunit` command via an npm script, which will automatically find the `qunit` program in your local `node_modules` folder, which is where npm keeps the dependencies you download. In your `package.json` file, specify it like so: @@ -75,7 +81,7 @@ ok 1 add > two numbers Congrats! You just wrote and executed your first QUnit test! -Check out the [API documentation](https://api.qunitjs.com) to learn about QUnit APIs for organising tests and making assertions. +Check out the [API documentation](./api/index.md) to learn about QUnit APIs for organising tests and making assertions. See [Command-line interface](./cli.md) for help with the `qunit` command. @@ -139,7 +145,7 @@ If you open this up in the browser you'll find a detailed report of the tests th Congrats! You just wrote and executed your first QUnit test! -Check out the [API documentation](https://api.qunitjs.com) to learn more about the QUnit APIs for organising tests and making assertions. +Check out the [API documentation](./api/index.md) to learn more about the QUnit APIs for organising tests and making assertions. ### Browser support diff --git a/upgrade-guide-2.x.md b/upgrade-guide-2.x.md index 141c6c6..c2b0196 100644 --- a/upgrade-guide-2.x.md +++ b/upgrade-guide-2.x.md @@ -19,21 +19,21 @@ The old methods are removed in QUnit 2.0 and replaced with placeholder methods t | QUnit 1.x | QUnit 2.x |--|-- -| `module()` | [`QUnit.module()`](https://api.qunitjs.com/QUnit/module/) -| `test()` | [`QUnit.test()`](https://api.qunitjs.com/QUnit/test/) -| `asyncTest()` | [`QUnit.test()`](https://api.qunitjs.com/QUnit/test/) with [`assert.async()`](https://api.qunitjs.com/assert/async/) -| `stop()`/`start()` | [`assert.async()`](https://api.qunitjs.com/assert/async/) -| `expect()` | [`assert.expect()`](https://api.qunitjs.com/assert/expect/) -| `ok()`, `equal()`, `deepEqual()`, … | [`assert`](https://api.qunitjs.com/assert/) -| `setup`/`teardown` options | [`beforeEach` and `afterEach` hooks](https://api.qunitjs.com/QUnit/module/#options-object) +| `module()` | [`QUnit.module()`](./api/QUnit/module.md) +| `test()` | [`QUnit.test()`](./api/QUnit/test.md) +| `asyncTest()` | [`QUnit.test()`](./api/QUnit/test.md) with [`assert.async()`](./api/assert/async.md) +| `stop()`/`start()` | [`assert.async()`](./api/assert/async.md) +| `expect()` | [`assert.expect()`](./api/assert/expect.md) +| `ok()`, `equal()`, `deepEqual()`, … | [`assert`](./api/assert/index.md) +| `setup`/`teardown` options | [`beforeEach` and `afterEach` hooks](./api/QUnit/module.md#options-object) For plugins and other integrations: | QUnit 1.x | QUnit 2.x |--|-- -| `QUnit.log = …`See also [`QUnit.on()`](https://api.qunitjs.com/callbacks/QUnit.on/), which implements the [js-reporters spec](https://github.com/js-reporters/js-reporters) since QUnit 2.2.
++ +See also [`QUnit.on()`](./api/callbacks/QUnit.on.md), which implements the [js-reporters spec](https://github.com/js-reporters/js-reporters) since QUnit 2.2. + +
Before: @@ -186,11 +190,11 @@ QUnit.log(function (results) { }); ``` -This applies to all reporting callbacks, specifically: [`begin`](https://api.qunitjs.com/callbacks/QUnit.begin/), [`done`](https://api.qunitjs.com/callbacks/QUnit.done/), [`log`](https://api.qunitjs.com/QUnit.log/), [`moduleDone`](https://api.qunitjs.com/callbacks/QUnit.moduleDone/), [`moduleStart`](https://api.qunitjs.com/callbacks/QUnit.moduleStart/), [`testDone`](https://api.qunitjs.com/callbacks/QUnit.testDone/), and [`testStart`](https://api.qunitjs.com/callbacks/QUnit.testStart/). +This applies to all reporting callbacks, specifically: [`begin`](./api/callbacks/QUnit.begin.md), [`done`](./api/callbacks/QUnit.done.md), [`log`](./api/callbacks/QUnit.log.md), [`moduleDone`](./api/callbacks/QUnit.moduleDone.md), [`moduleStart`](./api/callbacks/QUnit.moduleStart.md), [`testDone`](./api/callbacks/QUnit.testDone.md), and [`testStart`](./api/callbacks/QUnit.testStart.md). ### Replace `QUnit.push()` with `assert.pushResult()` -To implement custom assertions, assign functions to [`QUnit.assert`](https://api.qunitjs.com/config/QUnit.assert), and inside use [`this.pushResult()`](https://api.qunitjs.com/assert/pushResult) instead of `QUnit.push`. This allows assertions to be directly associated with its test context, preventing asynchronous tests from leaking into other tests. +To implement custom assertions, assign functions to [`QUnit.assert`](./api/extension/QUnit.assert.md), and inside use [`this.pushResult()`](./api/assert/pushResult.md) instead of `QUnit.push`. This allows assertions to be directly associated with its test context, preventing asynchronous tests from leaking into other tests. Before: @@ -250,7 +254,7 @@ QUnit.test('currentPage after replaceState', assert => { ### Renamed `QUnit.jsDump` to `QUnit.dump` -Originally `jsDump` was a standalone library imported into QUnit. It has since evolved further within the library. To reflect that, the property was renamed to [`QUnit.dump.parse`](https://api.qunitjs.com/config/QUnit.dump.parse/). This should only affect custom reporter code, not regular testsuites. +Originally `jsDump` was a standalone library imported into QUnit. It has since evolved further within the library. To reflect that, the property was renamed to [`QUnit.dump.parse`](./api/extension/QUnit.dump.parse.md). This should only affect custom reporter code, not regular testsuites. Before: @@ -295,7 +299,7 @@ QUnit.test('addition', assert => { ### Replace `assert.throws(Function, string, message)` signature -The signature of [`assert.throws()`](https://api.qunitjs.com/assert/throws/) that accepted an error string as second parameter has been removed. This avoids ambiguity with the assertion message, as both parameters were optional. +The signature of [`assert.throws()`](./api/assert/throws.md) that accepted an error string as second parameter has been removed. This avoids ambiguity with the assertion message, as both parameters were optional. It is recommended to use a regular expression or error object as the expected value instead. @@ -337,6 +341,6 @@ QUnit.test('add', assert => { }); ``` -See [`assert.throws()`](https://api.qunitjs.com/assert/throws/) for an overview of the supported signatures. +See [`assert.throws()`](./api/assert/throws.md) for an overview of the supported signatures. Note that in the two-argument signature `assert.throws(Function, string)` has always been interpreted as asserting _anything_ is thrown, with the string argument being the assertion message. This continues to be supported.