MCPcopy Create free account
hub / github.com/nodejs/node / getter

Method getter

lib/internal/test_runner/mock/mock.js:564–590  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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.

Callers 15

post-message.jsFile · 0.80
box2d.jsFile · 0.80
copy.jsFile · 0.80
zlib.jsFile · 0.80
lua_binarytrees.jsFile · 0.80
fannkuch.jsFile · 0.80
primes.jsFile · 0.80

Calls 1

methodMethod · 0.95

Tested by

no test coverage detected