Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2865cbb

Browse filesBrowse 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
Copy full SHA for 2865cbb

File tree

Expand file treeCollapse file tree

1 file changed

+10
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-8
lines changed
Open diff view settings
Collapse file

‎doc/api/assert.md‎

Copy file name to clipboardExpand all lines: doc/api/assert.md
+10-8Lines changed: 10 additions & 8 deletions
  • Display the source diff
  • Display the rich diff
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
const callsfunc = 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
const callsfunc = 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
const assert = require('node:assert');
469469

470+
const tracker = new assert.CallTracker();
471+
470472
function func() {}
471473
const callsfunc = 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.