I am using typescript with typeorm and i have an repository like this:
import { EntityRepository, getRepository, createQueryBuilder } from 'typeorm';
@EntityRepository()
export default class Repo {
async getSomething(): Promise<Result> {
const schemaQuery = getRepository(SomeModel)
.createQueryBuilder('sm')
.select(...)
.where(...);
.....
my test file is like this
import * as typeorm from 'typeorm';
import Repo from '../../../../src/repositories/Repo';
describe(
'test',
() => {
let repo: Repo;
beforeEach(() => {
repo = new Repo();
});
test('getSomething works', async () => {
jest.spyOn(typeorm, 'getRepository').mockImplementation(() => ({ // typescript wants me to implement all properties of getRepository which i dont want
createQueryBuilder: jest.fn(),
}));
...
});
},
);
how do i mock getRepository directly from typeorm which is still complying to typescript type check?