title: TypeORM connection not found on test
body: <p>I'm studying clean architecture with TDD by creating a simple application, and I'm trying to implement the UserRepository on my infrastructure layer, but I'm getting this error <code>ConnectionNotFoundError: Connection &quot;default&quot; was not found.</code> even after I've established a connection before running the test itself.</p>
  <p><a href="https://i.stack.imgur.com/h4wXg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h4wXg.png" alt="Jest Error" /></a></p>
  <p>This is my UserEntity class.</p>
  <pre class="lang-js prettyprint-override"><code>import { PrimaryColumn, Column, CreateDateColumn, UpdateDateColumn, Entity } from 'typeorm'
  
  @Entity('users')
  export class UserEntity {
    @PrimaryColumn('uuid')
    id: string
  
    @Column()
    name: string
  
    @Column({ unique: true })
    email: string
  
    @Column()
    password: string
  
    @CreateDateColumn()
    created_at: Date
  
    @UpdateDateColumn()
    updated_at: Date
  }
  
  </code></pre>
  <p>In this UserRepository, I'm implementing a <code>CreateUserRepository</code> that has the <code>create</code> methods below. To read the TypeORM repository I'm using the <code>getRepository</code> method from TypeORM</p>
  <pre class="lang-js prettyprint-override"><code>import { getRepository, Repository } from 'typeorm'
  
  import { CreateUserRepositoryDTO, CreateUserRepository } from '../../../../data/protocols/db/user/CreateUserRepository'
  import { UserModel } from '../../../../domain/models/UserModel'
  import { UserEntity } from '../entities/UserEntity'
  
  export class UserRepository implements CreateUserRepository {
    private ormRepository: Repository&lt;UserEntity&gt;
  
    constructor () {
      this.ormRepository = getRepository(UserEntity)
    }
  
    async create (userData: CreateUserRepositoryDTO): Promise&lt;UserModel&gt; {
      const user = await this.ormRepository.create(userData)
      const result = await this.ormRepository.save(user)
      return result
    }
  }
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>import { mockCreateUserRepositoryDTO } from '../../test/mockCreateUserRepositoryDTO'
  import { createTestConnection } from '../helpers/TypeORMHelper'
  import { UserRepository } from './UserRepository'
  
  describe('UserRepository', () =&gt; {
    it('Should return User on create Success', async () =&gt; {
      await createTestConnection()
      const userData = mockCreateUserRepositoryDTO()
      const sut = new UserRepository()
      const user = await sut.create(userData)
      console.log(user)
    })
  })
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>import { createConnection, Connection, ConnectionOptions } from 'typeorm'
  
  import { postgresCreds, schemaConfig } from '../../../../../ormconfig'
  
  async function createDbConnection (options: ConnectionOptions): Promise&lt;Connection&gt; {
    try {
      const connection: Connection = await createConnection(options)
      console.log(`TypeORM Connected to ${options.database}`)
      return connection
    } catch (err) {
      console.log('Problem with TypeORM connection')
      throw err.message
    }
  }
  
  export async function createTestConnection () {
    return createDbConnection({
      name: 'testConnection',
      type: 'postgres',
      database: 'market-list-test',
      synchronize: false,
      ...postgresCreds,
      ...schemaConfig,
      logging: ['error']
    })
  }
  
  </code></pre>