Skip to content

Commit 61edef5

Browse files
committed
Docs: Misc tweaks on Step API, config.testTimeout and Intro.
1 parent 764dc1a commit 61edef5

File tree

6 files changed

+50
-46
lines changed

6 files changed

+50
-46
lines changed

docs/api/assert/expect.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ Before, on QUnit 2.x without [QUnit.config.countStepsAsOne](../config/countSteps
3838
QUnit.test('example', async function (assert) {
3939
assert.expect(6);
4040

41-
MyWordParser.on('noun', function (word) {
41+
MyVoice.on('noun', function (word) {
4242
assert.step(word); // 1, 2, 3, 4
4343
});
44-
var song = await MyWordParser.sing('My Favorite Things', { lines: 1 });
44+
var song = await MyVoice.sing('My Favorite Things', { lines: 1 });
4545

4646
assert.true(song.finished, 'finished'); // 5
4747
assert.verifySteps([ // 6
@@ -59,10 +59,10 @@ After:
5959
QUnit.test('example', async function (assert) {
6060
assert.expect(2);
6161

62-
MyWordParser.on('noun', function (word) {
62+
MyVoice.on('noun', function (word) {
6363
assert.step(word);
6464
});
65-
var song = await MyWordParser.sing('My Favorite Things', { lines: 1 });
65+
var song = await MyVoice.sing('My Favorite Things', { lines: 1 });
6666

6767
assert.true(song.finished, 'finished'); // 1
6868
assert.verifySteps([ // 2

docs/api/assert/step.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,23 @@ The Step API provides an easy way to verify execution logic to a high degree of
2929

3030
```js
3131
QUnit.test('example', function (assert) {
32-
var maker = new WordMaker();
33-
maker.on('start', () => {
32+
const finder = new WordFinder();
33+
finder.on('start', () => {
3434
assert.step('start');
3535
});
36-
maker.on('data', (word) => {
36+
finder.on('data', (word) => {
3737
assert.step(word);
3838
});
39-
maker.on('end', () => {
39+
finder.on('end', () => {
4040
assert.step('end');
4141
});
42+
finder.on('error', message => {
43+
assert.step('error: ' + message);
44+
});
4245

43-
maker.process('3.1');
46+
finder.process('Hello, 3.1. Great!');
4447

45-
assert.verifySteps([ 'start', '3', 'point', '1', 'end' ]);
48+
assert.verifySteps(['start', 'Hello', 'Great', 'end']);
4649
});
4750
```
4851

docs/api/assert/verifySteps.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ The Step API provides an easy way to verify execution logic to a high degree of
2222

2323
For example, you can mark steps to observe and validate whether parts of your code are reached correctly, or to check the frequency (how often) an asynchronous code path is executed. You can also capture any unexpected steps, which are automatically detected and shown as part of the test failure.
2424

25-
This assertion compares a given array of string values to a list of previously recorded steps, as marked via previous calls to [`assert.step()`](./step.md).
25+
This assertion compares a given array of string values to a list of steps recorded via calls to [`assert.step()`](./step.md).
2626

27-
Calling `verifySteps()` will clear and reset the internal list of steps. This allows multiple independent sequences of `assert.step()` to exist within the same test.
27+
Calling `assert.verifySteps()` will clear and reset the internal list of steps. This allows multiple independent sequences of `assert.step()` to exist within the same test.
2828

29-
Refer to the below examples and learn how to use the Step API in your test suite.
29+
Refer to the below examples to learn how to use the Step API in your test suite.
3030

3131
## Changelog
3232

@@ -36,14 +36,14 @@ Refer to the below examples and learn how to use the Step API in your test suite
3636

3737
### Test event-based interface
3838

39-
This example uses a class based on an [`EventEmitter`](https://nodejs.org/api/events.html), such as the one provided by Node.js and other environments:
39+
These two examples test classes that emits event via an `on()` method. It might be based on an [`EventEmitter`](https://nodejs.org/api/events.html), such as the one found in Node.js and in other environments:
4040

4141
```js
4242
QUnit.test('good example', async function (assert) {
43-
MyWordParser.on('noun', function (word) {
43+
MyVoice.on('noun', function (word) {
4444
assert.step(word);
4545
});
46-
const song = await MyWordParser.sing('My Favorite Things', { lines: 1 });
46+
const song = await MyVoice.sing('My Favorite Things', { lines: 1 });
4747

4848
assert.true(song.finished, 'finished');
4949
assert.verifySteps([
@@ -57,23 +57,23 @@ QUnit.test('good example', async function (assert) {
5757

5858
```js
5959
QUnit.test('good example', async function (assert) {
60-
const maker = new WordMaker();
61-
maker.on('start', () => {
60+
const finder = new WordFinder();
61+
finder.on('start', () => {
6262
assert.step('start');
6363
});
64-
maker.on('data', (word) => {
64+
finder.on('data', (word) => {
6565
assert.step(word);
6666
});
67-
maker.on('end', () => {
67+
finder.on('end', () => {
6868
assert.step('end');
6969
});
70-
maker.on('error', message => {
70+
finder.on('error', message => {
7171
assert.step('error: ' + message);
7272
});
7373

74-
await maker.process('3.1');
74+
await finder.process('Hello, 3.1. Great!');
7575

76-
assert.verifySteps(['start', '3', 'point', '1', 'end']);
76+
assert.verifySteps(['start', 'Hello', 'Great', 'end']);
7777
});
7878
```
7979

@@ -82,17 +82,17 @@ If you approach this scenario *without* the Step API, one might be tempted to pl
8282
```js
8383
// WARNING: This is a BAD example
8484
QUnit.test('bad example 1', async function (assert) {
85-
const maker = new WordMaker();
86-
maker.on('start', () => {
85+
const finder = new WordFinder();
86+
finder.on('start', () => {
8787
assert.true(true, 'start');
8888
});
89-
maker.on('middle', () => {
89+
finder.on('middle', () => {
9090
assert.true(true, 'middle');
9191
});
92-
maker.on('end', () => {
92+
finder.on('end', () => {
9393
assert.true(true, 'end');
9494
});
95-
maker.on('error', () => {
95+
finder.on('error', () => {
9696
assert.true(false, 'error');
9797
});
9898

@@ -106,21 +106,21 @@ A less fragile approach could involve a local array that we check afterwards wit
106106
QUnit.test('manual example without Step API', async function (assert) {
107107
const values = [];
108108

109-
const maker = new WordMaker();
110-
maker.on('start', () => {
109+
const finder = new WordFinder();
110+
finder.on('start', () => {
111111
values.push('start');
112112
});
113-
maker.on('middle', () => {
113+
finder.on('middle', () => {
114114
values.push('middle');
115115
});
116-
maker.on('end', () => {
116+
finder.on('end', () => {
117117
values.push('end');
118118
});
119-
maker.on('error', () => {
119+
finder.on('error', () => {
120120
values.push('error');
121121
});
122122

123-
await maker.process();
123+
await finder.process();
124124

125125
assert.deepEqual(values, ['start', 'middle', 'end']);
126126
});

docs/api/config/testTimeout.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,9 @@ Individual tests can override the default `testTimeout` config via [assert.timeo
2828

2929
It is recommended to set the default at `3000` or higher (3 seconds). A lower timeout may cause intermittent failures due to unrelated infrastructure delays that are known to sometimes occur inside CI services and other virtual servers.
3030

31-
## Introducing a default timeout
32-
33-
Prior to QUnit 3, there has not been a default timeout. This meant that a test hang silently for many seconds or minutes before diagnostic details are presented (e.g. after a CI job reaches the maximum run time).
34-
35-
QUnit 3.0 will change the default timeout from undefined (Infinity) to 3 seconds.
36-
37-
### Deprecated: No timeout set
31+
## Deprecated: No timeout set
3832

39-
Starting in QUnit 2.21, a deprecation warning will be logged if a test takes longer than 3 seconds, when there is no timeout set.
33+
Starting in QUnit 2.21, a deprecation warning is logged if a test takes longer than 3 seconds, and there is no timeout set.
4034

4135
```
4236
Test {name} took longer than 3000ms, but no timeout was set.
@@ -63,7 +57,7 @@ You can address this warning before upgrading to QUnit 3 as follows:
6357

6458
* Or, your test runner of choice may offer other ways to set configuration.
6559

66-
For example, to set `testTimeout` via [karma-qunit](https://github.com/karma-runner/karma-qunit/#readme):
60+
For example, set `testTimeout` via [karma-qunit](https://github.com/karma-runner/karma-qunit/#readme):
6761

6862
```js
6963
config.set({
@@ -77,6 +71,12 @@ You can address this warning before upgrading to QUnit 3 as follows:
7771
});
7872
```
7973

74+
## Introducing a default timeout
75+
76+
Prior to QUnit 3.0, there has not been a default timeout. This meant that a test could hang silently for many seconds or minutes before diagnostic details are presented (e.g. after a CI job reaches the maximum run time).
77+
78+
QUnit 3.0 changes the default timeout from undefined (Infinity) to 3 seconds.
79+
8080
## Changelog
8181

8282
| [QUnit 2.21.0](https://github.com/qunitjs/qunit/releases/tag/2.21.0) | Announce change of default from undefined to `3000`, with a deprecation warning.

docs/api/reporters/console.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ runEnd {…}
4040
qunit --reporter console test/
4141
```
4242

43-
Enable manually in JavaScript code (since QUnit 2.16):
43+
Enable manually in JavaScript code:
4444

4545
```js
4646
QUnit.reporters.console.init(QUnit);
4747
```
4848

49-
Enable declaratively via [QUnit.config](../config/index.md) (since QUnit 3.0):
49+
Enable declaratively via [QUnit.config](../config/index.md):
5050

5151
```js
5252
// Preconfig:

docs/intro.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ redirect_from:
2020
Check these QUnit tutorials and examples, to make the most of your unit tests!
2121

2222
1. [QUnit.module](./api/QUnit/module.md#organizing-your-tests): How to group related tests.
23-
1. [QUnit.test](./api/QUnit/test.md#examples): Define tests, How to wait for async code
23+
1. [QUnit.test](./api/QUnit/test.md#examples): Define tests, How to wait for async code.
2424
1. [Fixture feature](./browser.md#fixture): Keeping your DOM tests atomic.
2525
1. [Step API](./api/assert/verifySteps.md): Testing asynchronous callbacks or event listeners.
2626
1. [Assertions](./api/assert/index.md): Partial object comparison, expected exceptions, and much more.
2727
1. [Browser](./browser.md): Productivity tricks, Browser automation, What can the toolbar do?
2828
1. [CLI](./cli.md): Productivity tricks, Code coverage.
2929
1. [Reporter API](./callbacks/QUnit.on.md#reporter-api): Event emitter, Create your own reporter.
30+
1. [Theme API](./browser.md#theme-api): Create your own theme.
3031

3132
## Support
3233

0 commit comments

Comments
 (0)