Skip to content

Commit 5e01d44

Browse files
authored
Merge pull request #54 from roypeled/fix-broken-class-parser
Fix broken class parser
2 parents 45bb8dc + ed1c6b0 commit 5e01d44

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@typestrong/ts-mockito",
3-
"version": "2.7.5",
3+
"version": "2.7.6",
44
"description": "Mocking library for TypeScript",
55
"main": "lib/ts-mockito.js",
66
"typings": "lib/ts-mockito",

src/utils/ObjectPropertyCodeRetriever.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class ObjectPropertyCodeRetriever {
1313
];
1414
} else if (typeof object[prop] === 'function') {
1515
const fnStr = String(object[prop]);
16-
const isMethod = fnStr.startsWith(prop);
16+
const isMethod = fnStr.startsWith(prop) || fnStr.startsWith(`async ${prop}`);
1717
return `
1818
${isMethod ? fnStr : `${prop}: ${fnStr}`}
1919
`;

test/mocking.types.spec.ts

+29-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { MethodToStub } from "../src/MethodToStub";
2-
import { instance, mock, when } from "../src/ts-mockito";
3-
import { Bar } from "./utils/Bar";
4-
import { ThenableClass } from "./utils/Thenable";
5-
import { EventEmitter } from "events";
1+
import {MethodToStub} from "../src/MethodToStub";
2+
import {instance, mock, when} from "../src/ts-mockito";
3+
import {Bar} from "./utils/Bar";
4+
import {ThenableClass} from "./utils/Thenable";
5+
import {EventEmitter} from "events";
66

77
describe("mocking", () => {
88
describe("mocking abstract class", () => {
@@ -228,19 +228,26 @@ describe("mocking", () => {
228228
});
229229
});
230230

231-
describe("mocking native class", () =>{
231+
describe("mocking native class", () => {
232232
it("should mock", () => {
233233
const mocked = mock(TestEmitter);
234234
expect(mocked).toBeDefined();
235235
});
236236
});
237237

238-
describe("mocking anon class", () =>{
238+
describe("mocking anon class", () => {
239239
it("should mock", () => {
240240
const mocked = mock(TestAnonClass);
241241
expect(mocked).toBeDefined();
242242
});
243243
});
244+
245+
describe("mocking async class", () => {
246+
it("should mock", () => {
247+
const mocked = mock(AsyncClass);
248+
expect(mocked).toBeDefined();
249+
});
250+
});
244251
});
245252

246253
abstract class SampleAbstractClass {
@@ -307,8 +314,21 @@ class SampleGeneric<T> {
307314
}
308315
}
309316

310-
class TestEmitter extends EventEmitter {}
317+
class TestEmitter extends EventEmitter {
318+
}
311319

312320
const TestAnonClass = class {
313321
private readonly foo = 'abc';
314-
};
322+
};
323+
324+
export class AsyncClass {
325+
public asyncValueArrowFn = async () => 'value';
326+
327+
public asyncValueFn = async function hello() {
328+
return 'value';
329+
};
330+
331+
public async returnAsyncValue(): Promise<number> {
332+
return 0;
333+
}
334+
}

0 commit comments

Comments
 (0)