我正在通过 inversify 工厂将自定义类以及 ioredis 注入我的类中:
import { inject } from 'inversify';
import * as Redis from 'ioredis';
import { MyOtherClass } from './MyOtherClass';
export class MyClass {
private redis!: Redis.Redis;
private myOther!: MyOtherClass;
constructor(@inject(TYPES.MYOTHERCLASS) private readonly myOtherFactory: () => Promise<MyOtherClass>,
@inject(TYPES.REDIS_FACTORY) private readonly redisFactory: () => Promise<Redis.Redis>) {
}
public async init(): Promise<void> {
this.myOther = await this.myOtherFactory();
console.log('a');
this.redis = await this.redisFactory();
console.log('b');
}
}
我正在测试文件中:
import 'mocha';
import { instance, mock } from 'ts-mockito';
import * as Redis from 'ioredis';
import { MyClass, MyOtherClass } from '../src';
describy('MyClass', () => {
let myClass: MyClass;
const mockedMyOther = mock(MyOtherClass);
const myOtherFactory = () => Promise.resolve(instance(mockedMyOther));
const mockedRedis = mock(Redis);
const redisFactory = () => Promise.resolve(instance(mockedRedis));
beforeEach( async () => {
myClass = new MyClass(myOtherFactory, redisFactory);
await myClass.init();
});
it('should init correctly');
});
运行测试时,它仅输出a
并在执行redisFactory
时超时。调试会话会在相同位置立即(静默地)终止。
没有其他信息可以提示我出了什么问题。
有什么想法吗?