Skip to content

Commit 2865cbb

Browse files
deokjinkimdanielleadams
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 <luigipinca@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 912eb30 commit 2865cbb

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎doc/api/assert.md‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ const callsfunc = tracker.calls(func);
346346
callsfunc(1, 2, 3);
347347

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

352352
```cjs
@@ -360,7 +360,7 @@ const callsfunc = tracker.calls(func);
360360
callsfunc(1, 2, 3);
361361

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

366366
### `tracker.report()`
@@ -397,7 +397,7 @@ function func() {}
397397
constcallsfunc=tracker.calls(func, 2);
398398

399399
// Returns an array containing information on callsfunc()
400-
tracker.report();
400+
console.log(tracker.report());
401401
// [
402402
// {
403403
// message: 'Expected the func function to be executed 2 time(s) but was
@@ -423,7 +423,7 @@ function func() {}
423423
constcallsfunc=tracker.calls(func, 2);
424424

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

459459
callsfunc();
460460
// Tracker was called once
461-
tracker.getCalls(callsfunc).length===1;
461+
assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
462462

463463
tracker.reset(callsfunc);
464-
tracker.getCalls(callsfunc).length===0;
464+
assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
465465
```
466466

467467
```cjs
468468
constassert=require('node:assert');
469469

470+
consttracker=newassert.CallTracker();
471+
470472
functionfunc() {}
471473
constcallsfunc=tracker.calls(func);
472474

473475
callsfunc();
474476
// Tracker was called once
475-
tracker.getCalls(callsfunc).length===1;
477+
assert.strictEqual(tracker.getCalls(callsfunc).length, 1);
476478

477479
tracker.reset(callsfunc);
478-
tracker.getCalls(callsfunc).length===0;
480+
assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
479481
```
480482

481483
### `tracker.verify()`

0 commit comments

Comments
 (0)