Inject TypeORM repository into NestJS service for mock data testing

前端 未结 3 1803
借酒劲吻你
借酒劲吻你 2020-11-27 18:12

There\'s a longish discussion about how to do this in this issue.

I\'ve experimented with a number of the proposed solutions but I\'m not having much luck.

C

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 18:52

    I also found that this worked for me:

    export const mockRepository = jest.fn(() => ({
      metadata: {
        columns: [],
        relations: [],
      },
    }));
    

    and

    const module: TestingModule = await Test.createTestingModule({
          providers: [{ provide: getRepositoryToken(Entity), useClass: mockRepository }],
        }).compile();
    

提交回复
热议问题