Skip to content

Commit e29a146

Browse files
deokjinkimRafaelGSS
authored andcommitted
doc: revise example of assert.CallTracker
In example of tracker.getCalls(), actual and expected are mismatched. So update expected value. In example of tracker.report(), user can check report easily through console.log(). In example of tracker.reset(), defining of tracker is missed in CJS. Plus, use assert.strictEqual() to check result. PR-URL: #47252 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 1fc62c7 commit e29a146

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

doc/api/assert.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ const callsfunc = tracker.calls(func);
348348
callsfunc(1, 2, 3);
349349

350350
assert.deepStrictEqual(tracker.getCalls(callsfunc),
351-
[{ thisArg: this, arguments: [1, 2, 3 ] }]);
351+
[{ thisArg: undefined, arguments: [1, 2, 3] }]);
352352
```
353353

354354
```cjs
@@ -362,7 +362,7 @@ const callsfunc = tracker.calls(func);
362362
callsfunc(1, 2, 3);
363363

364364
assert.deepStrictEqual(tracker.getCalls(callsfunc),
365-
[{ thisArg: this, arguments: [1, 2, 3 ] }]);
365+
[{ thisArg: undefined, arguments: [1, 2, 3] }]);
366366
```
367367

368368
### `tracker.report()`
@@ -399,7 +399,7 @@ function func() {}
399399
const callsfunc = tracker.calls(func, 2);
400400

401401
// Returns an array containing information on callsfunc()
402-
tracker.report();
402+
console.log(tracker.report());
403403
// [
404404
// {
405405
// message: 'Expected the func function to be executed 2 time(s) but was
@@ -425,7 +425,7 @@ function func() {}
425425
const callsfunc = tracker.calls(func, 2);
426426

427427
// Returns an array containing information on callsfunc()
428-
tracker.report();
428+
console.log(tracker.report());
429429
// [
430430
// {
431431
// message: 'Expected the func function to be executed 2 time(s) but was
@@ -462,24 +462,26 @@ const callsfunc = tracker.calls(func);
462462

463463
callsfunc();
464464
// Tracker was called once
465-
tracker.getCalls(callsfunc).length === 1;
465+
assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
466466

467467
tracker.reset(callsfunc);
468-
tracker.getCalls(callsfunc).length === 0;
468+
assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
469469
```
470470

471471
```cjs
472472
const assert = require('node:assert');
473473

474+
const tracker = new assert.CallTracker();
475+
474476
function func() {}
475477
const callsfunc = tracker.calls(func);
476478

477479
callsfunc();
478480
// Tracker was called once
479-
tracker.getCalls(callsfunc).length === 1;
481+
assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
480482

481483
tracker.reset(callsfunc);
482-
tracker.getCalls(callsfunc).length === 0;
484+
assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
483485
```
484486

485487
### `tracker.verify()`

0 commit comments

Comments
 (0)