From 3b542c53fe6c2f664b679ddac895bc873cb07d2e Mon Sep 17 00:00:00 2001 From: rezoled Date: Tue, 20 Aug 2024 13:09:37 +0300 Subject: [PATCH 1/3] 2.7.10 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index eadf5cf..d1fbf99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@typestrong/ts-mockito", - "version": "2.7.9", + "version": "2.7.10", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@typestrong/ts-mockito", - "version": "2.7.9", + "version": "2.7.10", "license": "MIT", "dependencies": { "@babel/parser": "^7.24.7", diff --git a/package.json b/package.json index de4c165..3f25295 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@typestrong/ts-mockito", - "version": "2.7.9", + "version": "2.7.10", "description": "Mocking library for TypeScript", "main": "lib/ts-mockito.js", "typings": "lib/ts-mockito", From 549f7a2d4bd2b063afb35c88ff321019e114ac16 Mon Sep 17 00:00:00 2001 From: rezoled Date: Tue, 20 Aug 2024 13:10:24 +0300 Subject: [PATCH 2/3] fixed proxies --- src/utils/ObjectPropertyCodeRetriever.ts | 3 ++- test/verification.spec.ts | 19 +++++++++++++++++++ tsconfig.json | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/utils/ObjectPropertyCodeRetriever.ts b/src/utils/ObjectPropertyCodeRetriever.ts index 74fd6f4..94c067c 100644 --- a/src/utils/ObjectPropertyCodeRetriever.ts +++ b/src/utils/ObjectPropertyCodeRetriever.ts @@ -12,7 +12,8 @@ export class ObjectPropertyCodeRetriever { descriptor?.set ? descriptor?.set.toString() : '', ]; } else if (typeof object[prop] === 'function') { - const fnStr = String(object[prop]); + let fnStr = String(object[prop]); + fnStr = fnStr.replace(/\[native code]/, ''); const gx = new RegExp(`^(async)?\\s{0,}\\*?${prop}`); const isMethod = gx.test(fnStr); return ` diff --git a/test/verification.spec.ts b/test/verification.spec.ts index 83264e1..34a956f 100644 --- a/test/verification.spec.ts +++ b/test/verification.spec.ts @@ -818,6 +818,25 @@ cases.forEach(testData => { } }); }); + + describe("decorator + Proxy", () => { + function decorator(target: unknown, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) { + const originalMethod = descriptor.value; + if (originalMethod !== undefined) { + descriptor.value = new Proxy(originalMethod, {}) + } + } + + class TestClass { + @decorator + foo() {} + } + + it("should mock", () => { + const mocked = mock(TestClass); + expect(mocked).toBeDefined(); + }); + }); }); }); diff --git a/tsconfig.json b/tsconfig.json index a622586..dcb7d62 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "experimentalDecorators": true, "outDir": "./lib", "module": "commonjs", "moduleResolution": "node", From 4370c840b44dfd383dbcba794dd14c7c4ec684b2 Mon Sep 17 00:00:00 2001 From: rezoled Date: Tue, 20 Aug 2024 13:11:19 +0300 Subject: [PATCH 3/3] 2.7.11 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index d1fbf99..b835517 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@typestrong/ts-mockito", - "version": "2.7.10", + "version": "2.7.11", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@typestrong/ts-mockito", - "version": "2.7.10", + "version": "2.7.11", "license": "MIT", "dependencies": { "@babel/parser": "^7.24.7", diff --git a/package.json b/package.json index 3f25295..6378ad9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@typestrong/ts-mockito", - "version": "2.7.10", + "version": "2.7.11", "description": "Mocking library for TypeScript", "main": "lib/ts-mockito.js", "typings": "lib/ts-mockito",