diff --git a/packages/core/src/utils/objects/methodsOf.spec.ts b/packages/core/src/utils/objects/methodsOf.spec.ts new file mode 100644 index 00000000000..2cde6209f40 --- /dev/null +++ b/packages/core/src/utils/objects/methodsOf.spec.ts @@ -0,0 +1,33 @@ +import {methodsOf} from "./methodsOf.js"; + +describe("methodsOf()", () => { + it("should return methods", () => { + class TestClass { + method() {} + + property: string; + } + + const methods = methodsOf(TestClass); + expect(methods).toHaveLength(1); + expect(methods[0]).toMatchObject({ + propertyKey: "method" + }); + }); + it("should not return getters", () => { + class TestClass { + method() {} + + get property() { + return ""; + } + } + + const methods = methodsOf(TestClass); + + expect(methods).toHaveLength(1); + expect(methods[0]).toMatchObject({ + propertyKey: "method" + }); + }); +}); diff --git a/packages/core/src/utils/objects/methodsOf.ts b/packages/core/src/utils/objects/methodsOf.ts index 04b24d0a953..7ef8d2e186a 100644 --- a/packages/core/src/utils/objects/methodsOf.ts +++ b/packages/core/src/utils/objects/methodsOf.ts @@ -1,6 +1,7 @@ import {Type} from "../../domain/Type.js"; import {ancestorsOf} from "./ancestorsOf.js"; import {classOf} from "./classOf.js"; +import {isSymbol} from "./isSymbol.js"; import {prototypeOf} from "./prototypeOf.js"; /** @@ -15,9 +16,9 @@ export function methodsOf(target: any): {target: Type; propertyKey: string}[] { const keys = Reflect.ownKeys(prototypeOf(target)); keys.forEach((propertyKey: string) => { - if (propertyKey !== "constructor") { - methods.set(propertyKey, {target, propertyKey}); - } + if (isSymbol(propertyKey) || propertyKey === "constructor" || Object.getOwnPropertyDescriptor(prototypeOf(target), propertyKey)?.get) + return; + methods.set(propertyKey, {target, propertyKey}); }); });