Skip to content

Commit

Permalink
doc: revise example of assert.CallTracker
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
deokjinkim authored and danielleadams committed Jul 6, 2023
1 parent 912eb30 commit 2865cbb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ const callsfunc = tracker.calls(func);
callsfunc(1, 2, 3);

assert.deepStrictEqual(tracker.getCalls(callsfunc),
[{ thisArg: this, arguments: [1, 2, 3 ] }]);
[{ thisArg: undefined, arguments: [1, 2, 3] }]);
```

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

assert.deepStrictEqual(tracker.getCalls(callsfunc),
[{ thisArg: this, arguments: [1, 2, 3 ] }]);
[{ thisArg: undefined, arguments: [1, 2, 3] }]);
```

### `tracker.report()`
Expand Down Expand Up @@ -397,7 +397,7 @@ function func() {}
const callsfunc = tracker.calls(func, 2);

// Returns an array containing information on callsfunc()
tracker.report();
console.log(tracker.report());
// [
// {
// message: 'Expected the func function to be executed 2 time(s) but was
Expand All @@ -423,7 +423,7 @@ function func() {}
const callsfunc = tracker.calls(func, 2);

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

callsfunc();
// Tracker was called once
tracker.getCalls(callsfunc).length === 1;
assert.strictEqual(tracker.getCalls(callsfunc).length, 1);

tracker.reset(callsfunc);
tracker.getCalls(callsfunc).length === 0;
assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
```

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

const tracker = new assert.CallTracker();

function func() {}
const callsfunc = tracker.calls(func);

callsfunc();
// Tracker was called once
tracker.getCalls(callsfunc).length === 1;
assert.strictEqual(tracker.getCalls(callsfunc).length, 1);

tracker.reset(callsfunc);
tracker.getCalls(callsfunc).length === 0;
assert.strictEqual(tracker.getCalls(callsfunc).length, 0);
```

### `tracker.verify()`
Expand Down

0 comments on commit 2865cbb

Please sign in to comment.