MCPcopy Create free account
hub / github.com/nodejs/node / #setupMock

Method #setupMock

lib/internal/test_runner/mock/mock.js:754–822  ·  view source on GitHub ↗
(ctx, fnToMatch)

Source from the content-addressed store, hash-verified

752 }
753
754 #setupMock(ctx, fnToMatch) {
755 const mock = new Proxy(fnToMatch, {
756 __proto__: null,
757 apply(_fn, thisArg, argList) {
758 const fn = FunctionPrototypeCall(nextImpl, ctx);
759 let result;
760 let error;
761
762 try {
763 result = ReflectApply(fn, thisArg, argList);
764 } catch (err) {
765 error = err;
766 throw err;
767 } finally {
768 FunctionPrototypeCall(trackCall, ctx, {
769 __proto__: null,
770 arguments: argList,
771 error,
772 result,
773 // eslint-disable-next-line no-restricted-syntax
774 stack: new Error(),
775 target: undefined,
776 this: thisArg,
777 });
778 }
779
780 return result;
781 },
782 construct(target, argList, newTarget) {
783 const realTarget = FunctionPrototypeCall(nextImpl, ctx);
784 let result;
785 let error;
786
787 try {
788 result = ReflectConstruct(realTarget, argList, newTarget);
789 } catch (err) {
790 error = err;
791 throw err;
792 } finally {
793 FunctionPrototypeCall(trackCall, ctx, {
794 __proto__: null,
795 arguments: argList,
796 error,
797 result,
798 // eslint-disable-next-line no-restricted-syntax
799 stack: new Error(),
800 target,
801 this: result,
802 });
803 }
804
805 return result;
806 },
807 get(target, property, receiver) {
808 if (property === 'mock') {
809 return ctx;
810 }
811

Callers 2

fnMethod · 0.95
methodMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected