From 7c048638bec088f831968d060a68885ff91747c5 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Sat, 25 Mar 2023 22:56:37 +0900 Subject: [PATCH 1/3] 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. --- doc/api/assert.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index d40300cc3fdb1b..9da74b8bc0b2c0 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -348,7 +348,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 @@ -362,7 +362,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()` @@ -399,7 +399,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 @@ -425,7 +425,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 @@ -462,24 +462,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()` From 486d2e752a185a024d1b18f7d1fc1e8e92df5980 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Mon, 27 Mar 2023 13:05:57 +0900 Subject: [PATCH 2/3] fix odd spacing in `arguments` --- doc/api/assert.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index 9da74b8bc0b2c0..0fbe11ca0a3711 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -348,7 +348,7 @@ const callsfunc = tracker.calls(func); callsfunc(1, 2, 3); assert.deepStrictEqual(tracker.getCalls(callsfunc), - [{ thisArg: undefined, arguments: [1, 2, 3 ] }]); + [{ thisArg: this, arguments: [1, 2, 3] }]); ``` ```cjs @@ -362,7 +362,7 @@ const callsfunc = tracker.calls(func); callsfunc(1, 2, 3); assert.deepStrictEqual(tracker.getCalls(callsfunc), - [{ thisArg: undefined, arguments: [1, 2, 3 ] }]); + [{ thisArg: undefined, arguments: [1, 2, 3] }]); ``` ### `tracker.report()` From a674cb4fc79c8fad8128a2a1ec78faae78c2b2d1 Mon Sep 17 00:00:00 2001 From: Deokjin Kim Date: Wed, 29 Mar 2023 23:00:41 +0900 Subject: [PATCH 3/3] use `undefined` instead of `this` for ESM Co-authored-by: Antoine du Hamel --- doc/api/assert.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index 0fbe11ca0a3711..1467d633c25ffd 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -348,7 +348,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