title: NestJS TypeORM InjectRepository Cannot read property 'prototype' of undefined
body: <p>Trying to unit test.
  Got following error:</p>
  
  <blockquote>
    <p>TypeError: Cannot read property 'prototype' of undefined</p>
    
    <p>export class UserService {</p>
    
    <p>constructor(@InjectRepository(User) private readonly userRepository:
    Repository &lt; User>) { } </p>
  </blockquote>
  
  <p><strong>spec.ts:</strong></p>
  
  <pre><code>describe('AuthController', () =&gt; {
  let authController: AuthController;
  let authService: AuthService;
  let mockRepository = {
  
  };
  beforeEach(async () =&gt; {
      const module = await Test.createTestingModule({
          imports: [
              TypeOrmModule.forFeature([User]),
          ],
          controllers: [AuthController],
          providers: [AuthService, {
              provide: getRepositoryToken(User),
              useValue: mockRepository
          }]
      }).compile()
      authService = module.get&lt;AuthService&gt;(AuthService);
      authController = module.get&lt;AuthController&gt;(AuthController)
  });
  </code></pre>
  
  <p>Can someone share a solution please?</p>
  
  <p><strong>MORE INFO</strong>:</p>
  
  <p>So seems like its something wrong with <code>typeorm</code></p>
  
  <pre><code>beforeEach(async () =&gt; {
      const module = await Test.createTestingModule({
  
      }).compile()
      authService = module.get&lt;AuthService&gt;(AuthService);
      authController = module.get&lt;AuthController&gt;(AuthController)
  });
  </code></pre>
  
  <p>With this code I'm getting exact the same error. So only problem is adding <code>typeorm</code> to this test Module.</p>
  
  <p>So it fails because of dependency: <strong>AuthController->AuthService->UserService->TypeORM</strong></p>
  
  <p>Btw just checked <code>UserService</code> using API with Postman and it works fine.</p>
  
  <p><strong>Still no result:</strong></p>
  
  <pre><code> module = await Test.createTestingModule({
          controllers: [AuthController],
          components: [
              {
                  provide: AuthService,
                  useValue: {}
              },
              {
                  provide: UserService,
                  useValue: {}
              },
              {
                  provide: getRepositoryToken(User),
                  useValue: {}
              }
          ],
          providers: [
              {
                  provide: AuthService,
                  useValue: {}
              },
              {
                  provide: UserService,
                  useValue: {}
              },
              {
                  provide: getRepositoryToken(User),
                  useValue: {}
              }
          ]
      }).compile()
      this.authController = module.get&lt;AuthController&gt;(AuthController)
  </code></pre>
  
  <p>Also </p>
  
  <pre><code>class AuthServiceMock {
      logIn(userName) {
          return { id:100, isDeleted:false, login:"login", password:"password"};
      }
  
      signUp() {
          return { expireIn: 3600, token:"token" };
      }
  }
  
  describe('AuthController', () =&gt; {
  let module: TestingModule;
  let authController: AuthController;
  let authService: AuthService;
  
  beforeEach(async () =&gt; {
      module = await Test.createTestingModule({
          controllers: [AuthController],
          components: [
  
          ],
          providers: [
              {
                  provide: AuthService,
                  useClass: AuthServiceMock
              },
          ]
      }).compile()
      this.authController = module.get&lt;AuthController&gt;(AuthController)
  });
  </code></pre>