Skip to content

Commit

Permalink
Merge pull request #57 from roypeled/fix-broken-class-parser
Browse files Browse the repository at this point in the history
added empty object test
  • Loading branch information
roypeled authored Jul 25, 2024
2 parents 946dd8e + 96a4e24 commit 4e3eb36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/utils/MockableFunctionsFinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,12 @@ export class MockableFunctionsFinder {
}

private getClassCodeAsStringWithInheritance(clazz: any) {
return [`const clazz = ${this.getClassAsString(clazz)}`, ...ObjectInspector.getObjectPrototypes(clazz.prototype).map(ObjectPropertyCodeRetriever.getObject)];
}

private getClassAsString(clazz: any) {
const classCode: string = typeof clazz.toString !== "undefined" ? clazz.toString() : "{}";
return [`const clazz = ${classCode}`, ...ObjectInspector.getObjectPrototypes(clazz.prototype).map(ObjectPropertyCodeRetriever.getObject)];
if(classCode === '[object Object]') return '{}';
return classCode;
}
}
7 changes: 7 additions & 0 deletions test/mocking.types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,13 @@ describe("mocking", () => {
expect(mocked).toBeDefined();
});
});

describe("mock empty object", () => {
it("should mock", () => {
const mocked = mock({});
expect(mocked).toBeDefined();
});
});
});

abstract class SampleAbstractClass {
Expand Down

0 comments on commit 4e3eb36

Please sign in to comment.