Skip to content

Commit

Permalink
Merge pull request #63 from roypeled/fix-broken-class-parser
Browse files Browse the repository at this point in the history
Fix broken class parser
  • Loading branch information
roypeled authored Sep 25, 2024
2 parents d815ba9 + d7c642f commit b39a6a0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typestrong/ts-mockito",
"version": "2.7.11",
"version": "2.7.12",
"description": "Mocking library for TypeScript",
"main": "lib/ts-mockito.js",
"typings": "lib/ts-mockito",
Expand Down
2 changes: 1 addition & 1 deletion src/utils/ObjectPropertyCodeRetriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ObjectPropertyCodeRetriever {
const gx = new RegExp(`^(async)?\\s{0,}\\*?${prop}`);
const isMethod = gx.test(fnStr);
return `
${isMethod ? fnStr : `${prop}: ${fnStr}`}
${isMethod ? fnStr : `"${prop}": ${fnStr}`}
`;
}
return '';
Expand Down
24 changes: 24 additions & 0 deletions test/verification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,30 @@ cases.forEach(testData => {
expect(mocked).toBeDefined();
});
});

describe("method names with special chars", () => {
class TestClass {
"special_chars-@?" = () => {
// do nothing
}
}

const TestObject = {
"special_chars-@?": () => {
// do nothing
}
}

it("should mock class", () => {
const mocked = mock(TestClass);
expect(mocked).toBeDefined();
});

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

Expand Down

0 comments on commit b39a6a0

Please sign in to comment.