title: How to test custom Repository in Nestjs/TypeORM applications
body: <p>I am trying to add more testing codes to improve the quality of my sample codes.</p>
  <p>Currently, I have a problem when testing <code>UserRepository</code> (<strong>not mock UserRepository</strong>),  there are some custom methods I added in my custom <code>UserRepository</code> like this.</p>
  <pre class="lang-js prettyprint-override"><code>@EntityRepository(UserEntity)
  export class UserRepository extends Repository&lt;UserEntity&gt; {
    findByEmail(email: string): Promise&lt;UserEntity&gt; {
      return this.findOne({ email: email });
    }
  }
  </code></pre>
  <p>So I want to verify the <code>findOne</code> is called from the parent <code>Repository</code>.</p>
  <p>I tried to add the following testing codes.</p>
  <pre class="lang-js prettyprint-override"><code>describe('UserRepository', () =&gt; {
    let local;
    let parentMock;
  
    beforeEach(() =&gt; {
      local = Object.getPrototypeOf(UserRepository);
      parentMock = {
        new: jest.fn(),
        construtor: jest.fn(),
        findOne: jest.fn(),
      };
      Object.setPrototypeOf(UserRepository, parentMock);
    });
  
    afterEach(() =&gt; {
      Object.setPrototypeOf(UserRepository, local);
    });
  
    it('should call findOne', async () =&gt; {
      const findByEmailSpy = jest.spyOn(parentMock, 'findOne');
      const users = new UserRepository();
      await users.findByEmail('test@example.com');
      expect(parentMock.mock.calls.length).toBe(1);
      expect(findByEmailSpy).toBeCalledWith({
        email: 'test@example.com',
      });
    });
  });
  </code></pre>
  <p>When running the tests, it complains there is no constructor() for <code>new UserRepository()</code>.</p>
  <p>Is there any way to fix this issue, or a better way to write these testing codes?</p>