0
votes

My nestjs project uses typeorm custom repositories.

@EntityRepository(MyEntity)
export class MyRepository extends AbstractRepository<MyEntity> {
    
    public operation1(entity) {

        /**
         * Few lines here   
        */
        this.manager.save(entity);
    }
 }

I am trying to write unit testcases using jest for the method operation1, But I am not able to mock this.manager.. Is there a way to mock this.manager. methods?

1

1 Answers

0
votes

If you are using Jest. Let's try this way:

let myRepository: Repository<MyRepository>;

jest
  .spyOn(myRepository, 'manage')
  .mockImplementation(() => Promise.resolve(entity);