我正在使用打字稿中的 jest/ts-jest 编写单元测试,我正在尝试模拟一个类,但我收到了 TypeError。“storage_1.default 不是构造函数”。
这是我嘲笑班级的方式。
index.test.ts
import GetAdaptiveCard from '../../GetAdaptiveCard/index'
const mockGetAdaptiveCard = jest.fn();
jest.mock('../../utils/storage', () => {
return jest.fn().mockImplementation(() => {
return {
getAdaptiveCard: mockGetAdaptiveCard
}
})
})
test('http trigger should return adaptive card', async () => {
....
await GetAdaptiveCard(context, req);//calls AdaptiveCardStorage. The class I am mocking in "../../utils/storage"
...
});
Run Code Online (Sandbox Code Playgroud)
索引.ts
import AdaptiveCardsStorage from '../utils/storage';
...
const storage: AdaptiveCardsStorage = new AdaptiveCardsStorage(); //This is where I get the TypeError
const adaptiveCard: string = await storage.getAdaptiveCard(userID, cardName); …Run Code Online (Sandbox Code Playgroud)