From 6dca9b906cd26d96086809a279933c93668ce59c 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 --- doc/api/test.md | 17 ++++++++ lib/internal/test_runner/mock.js | 24 +++++++++++ test/parallel/test-runner-mocking.js | 63 ++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/doc/api/test.md b/doc/api/test.md index 4d5c50f51ff8ec..d6e51fb1d51574 100644 --- a/doc/api/test.md +++ b/doc/api/test.md @@ -995,6 +995,22 @@ test('spies on an object method', (t) => { }); ``` +### `mock.getter(object, methodName[, implementation][, options])` + + + +This function is syntax sugar for [`MockTracker.method`][] with `options.getter` is `true`. + +### `mock.setter(object, methodName[, implementation][, options])` + + + +This function is syntax sugar for [`MockTracker.method`][] with `options.setter` is `true`. + ### `mock.reset()`