From 121f7e22adf1c736e6b50a92ddc4b6d6276fd995 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Fri, 12 Jul 2024 00:35:17 +0100 Subject: [PATCH] Docs: Recognise legacy idiom for `QUnit.test.if()` --- docs/api/QUnit/test.if.md | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/api/QUnit/test.if.md b/docs/api/QUnit/test.if.md index 96c1a86e4..6069ba050 100644 --- a/docs/api/QUnit/test.if.md +++ b/docs/api/QUnit/test.if.md @@ -16,14 +16,14 @@ Add a test that only runs if a condition is true. | parameter | description | |-----------|-------------| | `name` (string) | Title of unit being tested | -| `condition` (string) | Expression to decide if the test should be run | +| `condition` (string) | Expression to decide if the test should run | | `callback` (function) | Function that performs the test | If the condition is true, this is equivalent to calling [`QUnit.test()`](./test.md). If the conditional is false, this is equivalent to calling [`QUnit.test.skip()`](./test.skip.md), and test will not run. Instead, it will be listed in the results as a "skipped" test. -As a codebase becomes bigger, you may need to conditionally skip an entire group of tests. You can use [`QUnit.module.if()`](./module.md) to recursively skip all tests in a module based on a given condition. +As a codebase becomes bigger, you may need to conditionally skip an entire group of tests. You can use [`QUnit.module.if()`](./module.md) to recursively skip all tests in a module based on a given requirement. ## Examples @@ -41,7 +41,6 @@ QUnit.test.if('render', typeof document !== 'undefined', function (assert) { This is equivalent to: ```js -// Skip if executed without a DOM if (typeof document !== 'undefined') { QUnit.test('render', function (assert) { assert.strictEqual(MyApp.render(), '

Hello world!

'); @@ -60,3 +59,17 @@ QUnit.test('render', function (assert) { assert.strictEqual(MyApp.render(), '

Hello world!

'); }); ``` + +### Legacy idom + +Prior to QUnit 3.0, the following shortcuts were sometimes used. This may be replaced by `QUnit.test.if()`. + +```js +(typeof document !== 'undefined' ? QUnit.test : QUnit.skip)('example', function (assert) { + assert.true(true); +}); + +QUnit[typeof document !== 'undefined' ? 'test' : 'skip']('example', function (assert) { + assert.strue(true); +}); +```