title: Mock multiple TypeORM repositories in NestJS
body: <p>I'm having trouble to mock multiple repositories from different modules in NestJS.</p>
  
  <p>I'm using a <code>UsersRepository</code> from a <code>UsersModule</code> inside another module service (<code>NotesService</code>). The code is working fine, but I can't make the unit tests work.</p>
  
  <p>I have the following error: <code>Error: Nest can't resolve dependencies of the UserRepository (?). Please make sure that the argument Connection at index [0] is available in the TypeOrmModule context.</code></p>
  
  <h1>Minimal reproduction</h1>
  
  <pre><code>// [users.module.ts]
  
  @Module({
    imports: [TypeOrmModule.forFeature([User])],
    controllers: [UsersController],
    providers: [UsersService],
    exports: [UsersService],
  })
  export class UsersModule {}
  
  
  // [users.service.ts]
  
  @Injectable()
  export class UsersService {
    constructor(@InjectRepository(User) private usersRepository: UsersRepository) {}
    ...
  }
  
  
  // [notes.module.ts]
  
  @Module({
    imports: [
      TypeOrmModule.forFeature([Note, User]),
      UsersModule,
    ],
    controllers: [NotesController],
    providers: [NotesService],
  })
  export class NotesModule {
  }
  
  // [notes.service.ts]
  
  @Injectable()
  export class NotesService {
    constructor(
      @InjectRepository(Note) private notesRepository: NotesRepository,
      @InjectRepository(User) private usersRepository: UsersRepository,
    ) {}
    ...
  }
  </code></pre>
  
  <h2>Here is my unit test configuration:</h2>
  
  <pre><code>// [notes.service.spec.ts]
  
  beforeEach(async () =&gt; {
      const module = await Test.createTestingModule({
        imports: [UsersModule],
        providers: [
          NotesService,
          { provide: getRepositoryToken(Note), useFactory: repositoryMockFactory },
          { provide: getRepositoryToken(User), useFactory: repositoryMockFactory },
        ],
      }).compile();
  
      notesService = module.get&lt;NotesService&gt;(NotesService);
      notesRepositoryMock = module.get(getRepositoryToken(Note));
    });
  </code></pre>
  
  <p>The problem is I can't make a proper mock of the <code>UsersRepository</code> that comes from another module.</p>
  
  <p>I tried importing <code>TypeOrmModule</code> directly inside the test, and everything I could but I can't make it work.</p>