@noego/testing 0.7.2 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -405,6 +405,15 @@ function createMethodDecorator(registry) {
405
405
  throw new MethodNotCallableError(tokenLabel(token2), method);
406
406
  }
407
407
  }
408
+ if (Object.isExtensible(instance)) {
409
+ for (const [method, { entryKey, descriptor }] of effective) {
410
+ const original = instance[method];
411
+ const wrapped = buildMethodWrapper(instance, method, descriptor, registry.state(entryKey, method), original);
412
+ Object.defineProperty(instance, method, { value: wrapped, configurable: true, writable: true, enumerable: false });
413
+ }
414
+ wrappers.set(instance, instance);
415
+ return instance;
416
+ }
408
417
  const methodCache = /* @__PURE__ */ new Map();
409
418
  const proxy = new Proxy(instance, {
410
419
  get(target, prop, receiver) {
@@ -412,7 +421,7 @@ function createMethodDecorator(registry) {
412
421
  let wrapped = methodCache.get(prop);
413
422
  if (!wrapped) {
414
423
  const { entryKey, descriptor } = effective.get(prop);
415
- wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop));
424
+ wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop), target[prop]);
416
425
  methodCache.set(prop, wrapped);
417
426
  }
418
427
  return wrapped;
@@ -425,10 +434,9 @@ function createMethodDecorator(registry) {
425
434
  return proxy;
426
435
  };
427
436
  }
428
- function buildMethodWrapper(target, method, descriptor, state) {
437
+ function buildMethodWrapper(target, method, descriptor, state, original) {
429
438
  const callOriginal = (self, args) => {
430
- const fn = target[method];
431
- return fn.apply(self === void 0 ? target : self, args);
439
+ return original.apply(self === void 0 ? target : self, args);
432
440
  };
433
441
  if (typeof descriptor === "function") {
434
442
  const replacement = descriptor((...args) => callOriginal(target, args));