Skip to content

Commit 9ab52be

Browse files
authored
Docs: Modernize and improve documentation examples
* Docs: Modernize and improve documentation examples * Use modern syntax by default. Keep a few alternative "classic ES5 syntax" examples, explicitly described as such. * Consistent parameter naming test formatting. * Make the examples for `assert.timeout`, `assert.async`, `assert.verifySteps`, and `assert.pushResult` more appealing by replacing them with something that seems more reflecting of current best practices. * Point out that callback methods support async functions.
1 parent e142f44 commit 9ab52be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+595
-573
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ charset = utf-8
1010
trim_trailing_whitespace = true
1111
insert_final_newline = true
1212

13-
[*.yml]
13+
[*.{yml,md}]
1414
indent_style = space
1515
indent_size = 2

docs/Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ ruby RUBY_VERSION
44
# To upgrade, run `bundle update github-pages`.
55
gem "github-pages", group: :jekyll_plugins
66

7+
# Temporary fix for https://github.com/github/pages-gem/issues/752
8+
gem "webrick", "~> 1.7"
9+
710
gem 'jekyll-algolia', "1.6.0", group: :jekyll_plugins

docs/Gemfile.lock

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ GEM
99
zeitwerk (~> 2.2, >= 2.2.2)
1010
addressable (2.7.0)
1111
public_suffix (>= 2.0.2, < 5.0)
12-
algolia_html_extractor (2.6.2)
12+
algolia_html_extractor (2.6.4)
1313
json (~> 2.0)
14-
nokogiri (~> 1.10.4)
14+
nokogiri (~> 1.10)
1515
algoliasearch (1.27.5)
1616
httpclient (~> 2.8, >= 2.8.3)
1717
json (>= 1.5.1)
@@ -223,22 +223,24 @@ GEM
223223
rb-fsevent (~> 0.10, >= 0.10.3)
224224
rb-inotify (~> 0.9, >= 0.9.10)
225225
mercenary (0.3.6)
226-
mini_portile2 (2.4.0)
226+
mini_portile2 (2.5.0)
227227
minima (2.5.1)
228228
jekyll (>= 3.5, < 5.0)
229229
jekyll-feed (~> 0.9)
230230
jekyll-seo-tag (~> 2.1)
231-
minitest (5.14.2)
231+
minitest (5.14.3)
232232
multipart-post (2.1.1)
233-
nokogiri (1.10.10)
234-
mini_portile2 (~> 2.4.0)
233+
nokogiri (1.11.1)
234+
mini_portile2 (~> 2.5.0)
235+
racc (~> 1.4)
235236
octokit (4.20.0)
236237
faraday (>= 0.9)
237238
sawyer (~> 0.8.0, >= 0.5.3)
238239
pathutil (0.16.2)
239240
forwardable-extended (~> 2.6)
240241
progressbar (1.11.0)
241242
public_suffix (3.1.1)
243+
racc (1.5.2)
242244
rb-fsevent (0.10.4)
243245
rb-inotify (0.10.1)
244246
ffi (~> 1.0)
@@ -271,6 +273,7 @@ GEM
271273
unf_ext (0.0.7.7)
272274
unicode-display_width (1.7.0)
273275
verbal_expressions (0.1.5)
276+
webrick (1.7.0)
274277
zeitwerk (2.4.2)
275278

276279
PLATFORMS
@@ -279,9 +282,10 @@ PLATFORMS
279282
DEPENDENCIES
280283
github-pages
281284
jekyll-algolia (= 1.6.0)
285+
webrick (~> 1.7)
282286

283287
RUBY VERSION
284-
ruby 2.7.2p137
288+
ruby 3.0.0p0
285289

286290
BUNDLED WITH
287-
2.1.4
291+
2.2.3

docs/QUnit/start.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ version_added: "1.0"
1616

1717
When your async test has multiple exit points, call `QUnit.start()` for the corresponding number of `QUnit.stop()` increments.
1818

19-
### Example
19+
### Examples
2020

2121
A test run that does not begin when the page is done loading. This example uses an Asynchronous Module Definition (AMD) loader-style `require` call.
2222

2323
```js
2424
QUnit.config.autostart = false;
2525

26-
require(["test/tests1.js", "test/tests2.js"], function() {
27-
QUnit.start();
28-
});
26+
require(
27+
[ "test/tests1.js", "test/tests2.js" ],
28+
QUnit.start
29+
);
2930
```

docs/QUnit/test.only.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ When debugging a larger area of code, you may want to _only_ run all tests withi
4141
| [QUnit 2.12](https://github.com/qunitjs/qunit/releases/tag/2.12.0) | The `QUnit.only()` method was renamed to `QUnit.test.only()`.<br/>Use of `QUnit.only()` remains supported as an alias.
4242
| [QUnit 1.20](https://github.com/qunitjs/qunit/releases/tag/1.20.0) | The `QUnit.only()` method was introduced.
4343

44-
### Example
44+
### Examples
4545

4646
How to use `QUnit.test.only` to filter which tests are run.
4747

docs/QUnit/test.skip.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ As a codebase becomes bigger, you may sometimes want to temporarily disable an e
3333
| [QUnit 2.12](https://github.com/qunitjs/qunit/releases/tag/2.12.0) | The `QUnit.skip()` method was renamed to `QUnit.test.skip()`.<br/>Use of `QUnit.skip()` remains supported as an alias.
3434
| [QUnit 1.16](https://github.com/qunitjs/qunit/releases/tag/1.16.0) | The `QUnit.skip()` method was introduced.
3535

36-
### Example
36+
### Examples
3737

3838
How to use `skip` as a placeholder for future or temporarily broken tests.
3939

docs/QUnit/test.todo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ You can also use [`QUnit.module.todo()`](./module.md) to manage the "todo" state
3939
| [QUnit 2.12](https://github.com/qunitjs/qunit/releases/tag/2.12.0) | The `QUnit.todo()` method was renamed to `QUnit.test.todo()`.<br/>Use of `QUnit.todo()` remains supported as an alias.
4040
| [QUnit 2.2](https://github.com/qunitjs/qunit/releases/tag/2.2.0) | The `QUnit.todo()` method was introduced.
4141

42-
### Example
42+
### Examples
4343

4444
How to use `QUnit.test.todo` to denote code that is still under development.
4545

docs/assert/async.md

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,58 +28,72 @@ This replaces functionality previously provided by `QUnit.stop()` and [`QUnit.st
2828

2929
### Examples
3030

31-
Tell QUnit to wait for the `done()` call inside the timeout.
31+
##### Example: Wait for callback
32+
33+
Tell QUnit to wait for the `done()` call from a callback.
3234

3335
```js
34-
QUnit.test( "assert.async() test", function( assert ) {
35-
var done = assert.async();
36-
var input = $( "#test-input" ).focus();
37-
setTimeout(function() {
38-
assert.equal( document.activeElement, input[0], "Input was focused" );
36+
function fetchDouble( num, callback ) {
37+
const double = num * 2;
38+
callback( double );
39+
}
40+
41+
QUnit.test( "async example", assert => {
42+
const done = assert.async();
43+
44+
fetchDouble( 21, res => {
45+
assert.strictEqual( res, 42, "Result" );
3946
done();
4047
});
4148
});
4249
```
50+
##### Example: Wait for multiple callbacks
4351

44-
Call `assert.async()` for each operation. Each `done` callback can be called at most once.
52+
Call `assert.async()` multiple times to wait for multiple async operations. Each `done` callback must be called exactly once for the test to pass.
4553

4654
```js
47-
QUnit.test( "two async calls", function( assert ) {
48-
assert.expect( 2 );
55+
QUnit.test( "two async calls", assert => {
56+
const done1 = assert.async();
57+
const done2 = assert.async();
4958

50-
var done1 = assert.async();
51-
var done2 = assert.async();
52-
setTimeout(function() {
53-
assert.true( true, "test resumed from async operation 1" );
59+
fetchDouble( 3, res => {
60+
assert.strictEqual( res, 6, "double of 3" );
5461
done1();
55-
}, 500 );
56-
setTimeout(function() {
57-
assert.true( true, "test resumed from async operation 2" );
62+
});
63+
fetchDouble( 9, res => {
64+
assert.strictEqual( res, 18, "double of 9" );
5865
done2();
59-
}, 150);
66+
});
6067
});
6168
```
6269

63-
Set up an async test three exit points. Each `done()` call adds up to the `acceptCallCount`. After three calls, the test is done.
70+
##### Example: Require multiple calls
71+
72+
The `acceptCallCount` parameter can be used to require multiple calls to the same callback. In the below exxample, the test passes after exactly three calls.
6473

6574
```js
66-
QUnit.test( "multiple call done()", function( assert ) {
67-
assert.expect( 3 );
68-
var done = assert.async( 3 );
75+
function uploadBatch(batch, notify, complete) {
76+
batch.forEach( (item) => {
77+
// Do something with item
78+
notify();
79+
});
80+
complete(null)
81+
}
6982

70-
setTimeout(function() {
71-
assert.true( true, "first call done." );
72-
done();
73-
}, 500 );
83+
QUnit.test( "acceptCallCount example", assert => {
84+
assert.timeout( 1000 );
7485

75-
setTimeout(function() {
76-
assert.true( true, "second call done." );
77-
done();
78-
}, 500 );
86+
const notify = assert.async( 3 );
87+
const done = assert.async();
7988

80-
setTimeout(function() {
81-
assert.true( true, "third call done." );
82-
done();
83-
}, 500 );
89+
uploadBatch(
90+
[ "a", "b", "c" ],
91+
notify,
92+
(err) => {
93+
assert.strictEqual( err, null, "complete error parameter" );
94+
95+
done();
96+
}
97+
);
8498
});
8599
```

docs/assert/deepEqual.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,29 @@ The `deepEqual()` assertion can be used just like `equal()` when comparing the v
2929

3030
### Examples
3131

32-
Compare the value of two objects.
32+
Validate the properties and values of a given object.
33+
3334
```js
34-
QUnit.test( "deepEqual test", function( assert ) {
35-
var obj = { foo: "bar" };
35+
QUnit.test( "good example", assert => {
36+
const result = { foo: "bar" };
3637

37-
assert.deepEqual( obj, { foo: "bar" }, "Two objects can be the same in value" );
38+
assert.deepEqual( result, { foo: "bar" }, "result object" );
3839
});
3940
```
4041

4142
```js
42-
QUnit.test( 'deepEqual failing test', function( assert ) {
43-
assert.deepEqual( {
44-
a: 'Albert',
45-
b: 'Berta',
43+
QUnit.test( "bad example", assert => {
44+
const result = {
45+
a: "Albert",
46+
b: "Berta",
4647
num: 123
47-
}, {
48-
a: 'Albert',
49-
b: 'Berta',
50-
num: '123' // Fails: the number `123` is not strictly equal to the string `'123'`.
48+
};
49+
50+
// fails because the number 123 is not strictly equal to the string "123".
51+
assert.deepEqual( result, {
52+
a: "Albert",
53+
b: "Berta",
54+
num: "123"
5155
} );
5256
} );
5357
```

docs/assert/equal.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ version_added: "1.0"
1313

1414
`equal( actual, expected [, message ] )`
1515

16-
A non-strict value comparison.
16+
A non-strict comparison of two values.
1717

1818
| name | description |
1919
|--------------------|--------------------------------------|
@@ -25,6 +25,8 @@ A non-strict value comparison.
2525

2626
The `equal` assertion uses the simple comparison operator (`==`) to compare the actual and expected arguments. When they are equal, the assertion passes; otherwise, it fails. When it fails, both actual and expected values are displayed in the test result, in addition to a given message.
2727

28+
This method is similar to the `assertEquals()` method found in xUnit-style frameworks.
29+
2830
[`notEqual()`](./notEqual.md) can be used to explicitly test inequality.
2931

3032
[`strictEqual()`](./strictEqual.md) can be used to test strict equality.

0 commit comments

Comments
 (0)