From efc44567c96b7237219372d3bc48c5bda5e93e0a Mon Sep 17 00:00:00 2001 From: MURAKAMI Masahiko Date: Fri, 18 Nov 2022 18:31:49 +0900 Subject: [PATCH] test_runner: add getter and setter to MockTracker This commit allows tests in test runner to use the `getter` and `setter` methods as "syntax sugar" for `MockTracker.method` with the `options.getter` or `options.setter` set to true in the options. Refs: https://github.com/nodejs/node/pull/45326#discussion_r1014727289 PR-URL: https://github.com/nodejs/node/pull/45506 Reviewed-By: Moshe Atlow Reviewed-By: Colin Ihrig Reviewed-By: Antoine du Hamel --- doc/api/test.md | 19 ++++++ lib/internal/test_runner/mock.js | 54 +++++++++++++++++ test/parallel/test-runner-mocking.js | 87 ++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+) diff --git a/doc/api/test.md b/doc/api/test.md index 6bfff0c341bfa7..3588c6d6acd45b 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -941,6 +941,15 @@ test('mocks a counting function', (t) => { }); ``` +### `mock.getter(object, methodName[, implementation][, options])` + + + +This function is syntax sugar for [`MockTracker.method`][] with `options.getter` +set to `true`. + ### `mock.method(object, methodName[, implementation][, options])` + +This function is syntax sugar for [`MockTracker.method`][] with `options.setter` +set to `true`. + ## Class: `TapStream`