Skip to content

Commit

Permalink
Docs: Improve test.if() and test.skip() documentation
Browse files Browse the repository at this point in the history
* Make explicit that test.if() behaves as if deciding between
  test and test.skip.

* Clarify that skip() callback is optional, and has been since
  QUnit 1.0.0.
  • Loading branch information
Krinkle committed Jul 11, 2024
1 parent a4aa869 commit 0582796
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
17 changes: 17 additions & 0 deletions docs/api/QUnit/test.if.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ As a codebase becomes bigger, you may need to conditionally skip an entire group

## Examples

### Skip a test

```js
QUnit.module('MyApp');

Expand All @@ -36,6 +38,21 @@ 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>');
});
} else {
QUnit.test.skip('render');
}
```

### Conditional module

```js
QUnit.module.if('MyApp', typeof document !== 'undefined');

Expand Down
11 changes: 8 additions & 3 deletions docs/api/QUnit/test.skip.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ redirect_from:
version_added: "1.16.0"
---

`QUnit.test.skip( name )`<br/>
`QUnit.test.skip( name, callback )`<br/>
`QUnit.skip( name )`<br/>
`QUnit.skip( name, callback )`

Add a test that will be skipped during the run.

| parameter | description |
|-----------|-------------|
| `name` (string) | Title of unit being tested |
| `callback` (function) | Function that performs the test |
| `name` (string) | Title of unit |
| `callback` (function) | Optional, function that would perform the test |

Use this method to disable a [`QUnit.test()`](./test.md), as alternative to commenting out the test.

Expand All @@ -38,7 +40,7 @@ As a codebase becomes bigger, you may sometimes want to temporarily disable an e

## Examples

How to use `skip` as a placeholder for future or temporarily broken tests.
How to use `skip` as a placeholder for future tests, or to temporarily skip a broken test.

```js
QUnit.module('robot', hooks => {
Expand All @@ -55,5 +57,8 @@ QUnit.module('robot', hooks => {
QUnit.test.skip('laser', assert => {
assert.true(robot.laser());
});

// TODO: Implement this later!
QUnit.test.skip('jump');
});
```

0 comments on commit 0582796

Please sign in to comment.