Skip to content

Commit

Permalink
fix: ignore non-enumerable properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed May 19, 2022
1 parent d681abd commit d3c513b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-klass",
"version": "0.5.0",
"version": "0.5.1",
"description": "Type-strong klasses",
"main": "src/index.js",
"types": "src/index.d.ts",
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function splitBody(body) {
instanceMethods = [];
Object.entries(Object.getOwnPropertyDescriptors(body)).forEach(
([key, value]) => {
if (!value.enumerable) return;
if (key.startsWith("static "))
staticFields.push([key.replace(/^static /, ""), value]);
// TODO: `{ foo() {} }` and `{ foo: function () {} }` should be
Expand Down
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ describe("klass constructor", () => {
expect(cat.name).toBe("Fiona");
});

it("ignores non-enumerable properties", () => {
const body = {};
Object.defineProperty(body, "hidden", { value: 1 });
const Animal = klass(body);
expect(Animal().hidden).toBe(undefined);
});

describe("accepts getters & setters", () => {
test("klass", () => {
const Animal = klass({
Expand Down

0 comments on commit d3c513b

Please sign in to comment.