Last active
May 23, 2023 19:55
-
-
Save theusindabike/8e66b4c89d5dd278e085fb10ab1970ee to your computer and use it in GitHub Desktop.
override datasource provider to use pg-mem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as request from 'supertest'; | |
import { Test } from '@nestjs/testing'; | |
import { INestApplication } from '@nestjs/common'; | |
import { DataSource } from 'typeorm'; | |
import { setupDatabase } from '../setup-database'; | |
import { AppModule } from '../../src/app.module'; | |
import { TransactionRepository } from '../../src/transactions/repository/transactions.repository'; | |
describe('TransactionController (e2e)', () => { | |
let app: INestApplication; | |
let dataSource: DataSource; | |
let transactionRepository: TransactionRepository; | |
beforeAll(async () => { | |
dataSource = await setupDatabase(); | |
const moduleFixture = await Test.createTestingModule({ | |
imports: [AppModule], | |
providers: [TransactionRepository], | |
}) | |
.overrideProvider(DataSource) | |
.useValue(dataSource) | |
.compile(); | |
app = moduleFixture.createNestApplication(); | |
transactionRepository = moduleFixture.get<TransactionRepository>( | |
TransactionRepository, | |
); | |
await app.init(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment