Skip to content

Commit

Permalink
Docs: Recognise legacy idiom for QUnit.test.if()
Browse files Browse the repository at this point in the history
  • Loading branch information
Krinkle committed Jul 11, 2024
1 parent a448b03 commit 121f7e2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions docs/api/QUnit/test.if.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(), '<p>Hello world!</p>');
Expand All @@ -60,3 +59,17 @@ QUnit.test('render', function (assert) {
assert.strictEqual(MyApp.render(), '<p>Hello world!</p>');
});
```

### 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);
});
```

0 comments on commit 121f7e2

Please sign in to comment.