Skip to content

Instantly share code, notes, and snippets.

@theusindabike
Last active May 23, 2023 19:55
Show Gist options
  • Save theusindabike/8e66b4c89d5dd278e085fb10ab1970ee to your computer and use it in GitHub Desktop.
Save theusindabike/8e66b4c89d5dd278e085fb10ab1970ee to your computer and use it in GitHub Desktop.
override datasource provider to use pg-mem
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