MCPcopy Index your code
hub / github.com/nodejs/node / constructor

Method constructor

lib/internal/test_runner/mock/mock.js:299–332  ·  view source on GitHub ↗
(object, propertyName, value)

Source from the content-addressed store, hash-verified

297 #onceValues;
298
299 constructor(object, propertyName, value) {
300 this.#onceValues = new SafeMap();
301 this.#accesses = [];
302 this.#object = object;
303 this.#propertyName = propertyName;
304 this.#originalValue = object[propertyName];
305 this.#value = arguments.length > 2 ? value : this.#originalValue;
306 this.#descriptor = ObjectGetOwnPropertyDescriptor(object, propertyName);
307 if (!this.#descriptor) {
308 throw new ERR_INVALID_ARG_VALUE(
309 'propertyName', propertyName, 'is not a property of the object',
310 );
311 }
312
313 const { configurable, enumerable } = this.#descriptor;
314 ObjectDefineProperty(object, propertyName, {
315 __proto__: null,
316 configurable,
317 enumerable,
318 get: () => {
319 const nextValue = this.#getAccessValue(this.#value);
320 const access = {
321 __proto__: null,
322 type: 'get',
323 value: nextValue,
324 // eslint-disable-next-line no-restricted-syntax
325 stack: new Error(),
326 };
327 ArrayPrototypePush(this.#accesses, access);
328 return nextValue;
329 },
330 set: this.mockImplementation.bind(this),
331 });
332 }
333
334 /**
335 * Gets an array of recorded accesses (get/set) to the property.

Callers

nothing calls this directly

Calls 2

#getAccessValueMethod · 0.95
bindMethod · 0.45

Tested by

no test coverage detected