Skip to content

Commit 38d07f3

Browse files
committed
Docs: Use parens in arrow functions, and overall reduce arrows funcs
Cut back the use of arrow functins somewhat, especially in migration guides from older versions, and in generic examples that aren't about scope. When we use them, consistency use parentheses around the arguments. Remove the `hooks => ` and `assert => ` idiom from examples which have not taken off in practice, and don't jive well with most practical style guides. It may seem minimal, but it makes the code not realistic and not directly portable. It also makes it harder to adopt, e.g. to add an argument such as the case when using `QUnit.test.each()`.
1 parent 81db1c6 commit 38d07f3

26 files changed

+67
-67
lines changed

docs/api/QUnit/module.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ QUnit.module.skip('Robot', (hooks) => {
249249
android = new Robot();
250250
});
251251

252-
QUnit.test('hello', (assert) => {
252+
QUnit.test('hello', function (assert) {
253253
assert.strictEqual(android.hello(), 'Hello, my name is AN-2178!');
254254
});
255255
});
@@ -274,7 +274,7 @@ QUnit.module.only('Robot', (hooks) => {
274274
android = new Robot();
275275
});
276276

277-
QUnit.test('hello', (assert) => {
277+
QUnit.test('hello', function (assert) {
278278
assert.strictEqual(android.hello(), 'Hello, my name is AN-2178!');
279279
});
280280
});
@@ -289,7 +289,7 @@ QUnit.module.todo('Robot', (hooks) => {
289289
android = new Robot();
290290
});
291291

292-
QUnit.test('hello', (assert) => {
292+
QUnit.test('hello', function (assert) {
293293
assert.strictEqual(android.hello(), 'Hello');
294294
// TODO
295295
// Actual: Goodbye

docs/api/QUnit/test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function square (x) {
5454
return x * x;
5555
}
5656

57-
QUnit.test('square()', (assert) => {
57+
QUnit.test('square()', function (assert) {
5858
assert.equal(square(2), 4);
5959
assert.equal(square(3), 9);
6060
});
@@ -67,7 +67,7 @@ Following the example above, `QUnit.test` also supports JS [async functions][] s
6767
[async functions]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function
6868

6969
```js
70-
QUnit.test('Test with async-await', async (assert) => {
70+
QUnit.test('Test with async-await', async function (assert) {
7171
const a = await fetchSquare(2);
7272
const b = await fetchSquare(3);
7373

docs/api/QUnit/test.only.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ When debugging a larger area of code, you may want to expand your filter to run
4545
How to use `QUnit.test.only` to filter which tests are run.
4646

4747
```js
48-
QUnit.module('robot', hooks => {
48+
QUnit.module('robot', (hooks) => {
4949
let robot;
5050
hooks.beforeEach(() => {
5151
robot = new Robot();
5252
});
5353

54-
QUnit.test('say()', assert => {
54+
QUnit.test('say()', (assert) => {
5555
assert.true(robot.say('Hello'));
5656
});
5757

5858
// Run only this test
5959
// For example, you are working on changing this method.
60-
QUnit.test.only('laser()', assert => {
60+
QUnit.test.only('laser()', (assert) => {
6161
assert.true(robot.laser());
6262
});
6363

64-
QUnit.test('take()', assert => {
64+
QUnit.test('take()', (assert) => {
6565
assert.true(robot.take(5));
6666
});
6767
});

docs/api/QUnit/test.skip.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ As a codebase becomes bigger, you may sometimes want to temporarily disable an e
4343
How to use `skip` as a placeholder for future tests, or to temporarily skip a broken test.
4444

4545
```js
46-
QUnit.module('robot', hooks => {
46+
QUnit.module('robot', (hooks) => {
4747
let robot;
4848
hooks.beforeEach(() => {
4949
robot = new Robot();
5050
});
5151

52-
QUnit.test('say', assert => {
52+
QUnit.test('say', (assert) => {
5353
assert.strictEqual(robot.say(), 'Exterminate!');
5454
});
5555

5656
// Robot does not yet have a laser() method yet, skip this test for now
57-
QUnit.test.skip('laser', assert => {
57+
QUnit.test.skip('laser', (assert) => {
5858
assert.true(robot.laser());
5959
});
6060

docs/api/QUnit/test.todo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ You can also use [`QUnit.module.todo()`](./module.md) to manage the "todo" state
4343
How to use `QUnit.test.todo` to denote code that is still under development.
4444

4545
```js
46-
QUnit.module('Robot', hooks => {
46+
QUnit.module('Robot', (hooks) => {
4747
let robot;
4848
hooks.beforeEach(() => {
4949
robot = new Robot();
5050
});
5151

5252
// Robot is not yet finished
53-
QUnit.test.todo('fireLazer', assert => {
53+
QUnit.test.todo('fireLazer', (assert) => {
5454
const result = robot.fireLazer();
5555
assert.equal(result, "I'm firing my lazer!");
5656
});

docs/api/assert/async.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ function fetchDouble (num, callback) {
4040
callback(double);
4141
}
4242

43-
QUnit.test('async example', assert => {
43+
QUnit.test('async example', function (assert) {
4444
const done = assert.async();
4545

46-
fetchDouble(21, res => {
46+
fetchDouble(21, (res) => {
4747
assert.strictEqual(res, 42, 'Result');
4848
done();
4949
});
@@ -54,15 +54,15 @@ QUnit.test('async example', assert => {
5454
Call `assert.async()` multiple times to wait for multiple async operations. Each `done` callback must be called exactly once for the test to pass.
5555

5656
```js
57-
QUnit.test('two async calls', assert => {
57+
QUnit.test('two async calls', function (assert) {
5858
const done1 = assert.async();
5959
const done2 = assert.async();
6060

61-
fetchDouble(3, res => {
61+
fetchDouble(3, (res) => {
6262
assert.strictEqual(res, 6, 'double of 3');
6363
done1();
6464
});
65-
fetchDouble(9, res => {
65+
fetchDouble(9, (res) => {
6666
assert.strictEqual(res, 18, 'double of 9');
6767
done2();
6868
});
@@ -82,7 +82,7 @@ function uploadBatch (batch, notify, complete) {
8282
complete(null);
8383
}
8484

85-
QUnit.test('multiple calls example', assert => {
85+
QUnit.test('multiple calls example', function (assert) {
8686
assert.timeout(1000);
8787

8888
const notify = assert.async(3);

docs/api/assert/closeTo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ To learn how floating-point numbers work internally, refer to [Double-precision
3131
## Examples
3232

3333
```js
34-
QUnit.test('good example', assert => {
34+
QUnit.test('good example', function (assert) {
3535
const x = 0.1 + 0.2; // 0.30000000000000004
3636

3737
// passing: must be between 0.299 and 0.301
@@ -42,7 +42,7 @@ QUnit.test('good example', assert => {
4242
assert.closeTo(y, 20.10, 0.05);
4343
});
4444

45-
QUnit.test('bad example', assert => {
45+
QUnit.test('bad example', function (assert) {
4646
const x = 20.7;
4747
// failing: must be between 20.0 and 20.2 inclusive
4848
assert.closeTo(x, 20.1, 0.1);

docs/api/assert/deepEqual.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ To assert strict equality on own properties only, refer to [`assert.propEqual()`
3636

3737
```js
3838
function makeComplexObject (name, extra, country) {
39-
var children = new Set();
39+
const children = new Set();
4040
children.add('Alice');
4141
children.add(extra);
42-
var countryToCapital = { UK: 'London' };
42+
const countryToCapital = { UK: 'London' };
4343
return {
4444
name: name,
4545
children: children,
@@ -51,7 +51,7 @@ function makeComplexObject (name, extra, country) {
5151
}
5252

5353
QUnit.test('object example', function (assert) {
54-
var result = makeComplexObject('Marty', 'Bob', 'UK');
54+
const result = makeComplexObject('Marty', 'Bob', 'UK');
5555

5656
// Succeeds!
5757
// While each object is distinct by strict equality (identity),
@@ -91,7 +91,7 @@ class BaseCoord {
9191
class PrimaryDimensionCoord extends BaseCoord {}
9292
class UpsideDownCoord extends BaseCoord {}
9393

94-
QUnit.test('class example', assert => {
94+
QUnit.test('class example', function (assert) {
9595
eleven.goto('Enschede');
9696
eleven.enterGate();
9797
const loc = eleven.getLocation();
@@ -105,7 +105,7 @@ QUnit.test('class example', assert => {
105105
```
106106

107107
```js
108-
QUnit.test('failing example', assert => {
108+
QUnit.test('failing example', function (assert) {
109109
const result = {
110110
a: 'Albert',
111111
b: 'Berta',

docs/api/assert/false.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This method is similar to the `assertFalse()` method found in xUnit-style framew
2727
## Examples
2828

2929
```js
30-
QUnit.test('example', assert => {
30+
QUnit.test('example', function (assert) {
3131
// success
3232
assert.false(false, 'boolean false');
3333

docs/api/assert/notDeepEqual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ This is the inverse of [`assert.deepEqual()`](./deepEqual.md).
3131
Compare the value of two objects.
3232

3333
```js
34-
QUnit.test('example', assert => {
34+
QUnit.test('example', function (assert) {
3535
const result = { foo: 'yep' };
3636

3737
// succeeds, objects are similar but have a different foo value.

0 commit comments

Comments
 (0)