* Mocks a getter method of an object. * This is a syntax sugar for the MockTracker.method with options.getter set to true * @param {object} object - The target object. * @param {string} methodName - The name of the getter method to be mocked. * @param {Function} [implementation] - An opt
(
object,
methodName,
implementation = kDefaultFunction,
options = kEmptyObject,
)
| 562 | * @returns {ProxyConstructor} The mock method tracker. |
| 563 | */ |
| 564 | getter( |
| 565 | object, |
| 566 | methodName, |
| 567 | implementation = kDefaultFunction, |
| 568 | options = kEmptyObject, |
| 569 | ) { |
| 570 | if (implementation !== null && typeof implementation === 'object') { |
| 571 | options = implementation; |
| 572 | implementation = kDefaultFunction; |
| 573 | } else { |
| 574 | validateObject(options, 'options'); |
| 575 | } |
| 576 | |
| 577 | const { getter = true } = options; |
| 578 | |
| 579 | if (getter === false) { |
| 580 | throw new ERR_INVALID_ARG_VALUE( |
| 581 | 'options.getter', getter, 'cannot be false', |
| 582 | ); |
| 583 | } |
| 584 | |
| 585 | return this.method(object, methodName, implementation, { |
| 586 | __proto__: null, |
| 587 | ...options, |
| 588 | getter, |
| 589 | }); |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * Mocks a setter method of an object. |
no test coverage detected