* Creates a property tracker for a specified object. * @param {(object)} object - The object whose value is being tracked. * @param {string} propertyName - The identifier of the property on object to be tracked. * @param {any} value - An optional replacement value used as the mock value for
(
object,
propertyName,
value,
)
| 704 | * @returns {ProxyConstructor} The mock property tracker. |
| 705 | */ |
| 706 | property( |
| 707 | object, |
| 708 | propertyName, |
| 709 | value, |
| 710 | ) { |
| 711 | validateObject(object, 'object'); |
| 712 | validateStringOrSymbol(propertyName, 'propertyName'); |
| 713 | |
| 714 | const ctx = arguments.length > 2 ? |
| 715 | new MockPropertyContext(object, propertyName, value) : |
| 716 | new MockPropertyContext(object, propertyName); |
| 717 | ArrayPrototypePush(this.#mocks, { |
| 718 | __proto__: null, |
| 719 | ctx, |
| 720 | restore: restoreProperty, |
| 721 | }); |
| 722 | |
| 723 | return new Proxy(object, { |
| 724 | __proto__: null, |
| 725 | get(target, property, receiver) { |
| 726 | if (property === 'mock') { |
| 727 | return ctx; |
| 728 | } |
| 729 | return ReflectGet(target, property, receiver); |
| 730 | }, |
| 731 | }); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * Resets the mock tracker, restoring all mocks and clearing timers. |
no test coverage detected