From b942f93b5bfd70ad8f245c94048cfaffda4ee56a Mon Sep 17 00:00:00 2001 From: MURAKAMI Masahiko Date: Fri, 18 Nov 2022 18:31:49 +0900 Subject: [PATCH] feat: 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 (cherry picked from commit afed1afa55962211b6b56c2068d520b4d8a08888) --- README.md | 19 ++++++ lib/internal/test_runner/mock.js | 56 ++++++++++++++++- test/parallel/test-runner-mocking.js | 89 +++++++++++++++++++++++++++- 3 files changed, 162 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ff8afc..10cd238 100644 --- a/README.md +++ b/README.md @@ -866,6 +866,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`