@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.js CHANGED
@@ -350,6 +350,15 @@ function createMethodDecorator(registry) {
350
350
  throw new MethodNotCallableError(tokenLabel(token2), method);
351
351
  }
352
352
  }
353
+ if (Object.isExtensible(instance)) {
354
+ for (const [method, { entryKey, descriptor }] of effective) {
355
+ const original = instance[method];
356
+ const wrapped = buildMethodWrapper(instance, method, descriptor, registry.state(entryKey, method), original);
357
+ Object.defineProperty(instance, method, { value: wrapped, configurable: true, writable: true, enumerable: false });
358
+ }
359
+ wrappers.set(instance, instance);
360
+ return instance;
361
+ }
353
362
  const methodCache = /* @__PURE__ */ new Map();
354
363
  const proxy = new Proxy(instance, {
355
364
  get(target, prop, receiver) {
@@ -357,7 +366,7 @@ function createMethodDecorator(registry) {
357
366
  let wrapped = methodCache.get(prop);
358
367
  if (!wrapped) {
359
368
  const { entryKey, descriptor } = effective.get(prop);
360
- wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop));
369
+ wrapped = buildMethodWrapper(target, prop, descriptor, registry.state(entryKey, prop), target[prop]);
361
370
  methodCache.set(prop, wrapped);
362
371
  }
363
372
  return wrapped;
@@ -370,10 +379,9 @@ function createMethodDecorator(registry) {
370
379
  return proxy;
371
380
  };
372
381
  }
373
- function buildMethodWrapper(target, method, descriptor, state) {
382
+ function buildMethodWrapper(target, method, descriptor, state, original) {
374
383
  const callOriginal = (self, args) => {
375
- const fn = target[method];
376
- return fn.apply(self === void 0 ? target : self, args);
384
+ return original.apply(self === void 0 ? target : self, args);
377
385
  };
378
386
  if (typeof descriptor === "function") {
379
387
  const replacement = descriptor((...args) => callOriginal(target, args));