我已经写了一个模拟程序,可以很好地工作,但我不能让它与@ts-ignore一起工作
describe('findAll', () => {
it('should get all networks of the user', async () => {
const userId = uuid();
const allNetworksFromRepo = Array(3).fill(networkDataBuilder());
const expectedNetworks = allNetworksFromRepo;
const createQueryBuilder = jest
.spyOn(networkRepo, 'createQueryBuilder')
// @ts-ignore
.mockImplementation(() => ({
innerJoin: jest.fn().mockReturnThis(),
where: jest.fn().mockReturnThis(),
getMany: jest.fn().mockReturnValue(allNetworksFromRepo),
}));
const retrievedNetworks = await service.findAll(userId);
expect(createQueryBuilder).toHaveBeenCalled();
expect(retrievedNetworks).toStrictEqual(expectedNetworks);
});TS2345: Argument of type
'() => { innerJoin: jest.Mock<any, any>; where: jest.Mock<any, any>; getMany: jest.Mock<any, any>; }'
is not assignable to parameter of type
'(alias?: string | undefined, queryRunner?: QueryRunner | undefined) => SelectQueryBuilder<Network>'.
Type
'{ innerJoin: Mock<any, any>; where: Mock<any, any>; getMany: Mock<any, any>; }'
is missing the following properties from type
'SelectQueryBuilder<Network>': getQuery, subQuery, select, addSelect, and 94 more.发布于 2021-05-01 00:14:09
这是一行代码。这个解决方案怎么样?
// @ts-ignore
const createQueryBuilder = jest
.spyOn(networkRepo, 'createQueryBuilder')
.mockImplementation(() => ({
innerJoin: jest.fn().mockReturnThis(),
where: jest.fn().mockReturnThis(),
getMany: jest.fn().mockReturnValue(allNetworksFromRepo),
}));https://stackoverflow.com/questions/67336619
复制相似问题