Writing Integration Tests β
Bootstrap β
Create a *.spec.ts file in the relevant module directory and extend BaseIntegrationTest:
typescript
import {
BaseIntegrationTest,
TIMEOUTS,
} from '../../test/utils/base-integration.spec';
const testContext = new BaseIntegrationTest();
beforeAll(async () => {
await testContext.beforeAll();
// Pull services from the DI container if needed:
// const myService = testContext.app.get(MyService);
}, TIMEOUTS.all);
afterAll(() => testContext.afterAll(), TIMEOUTS.all);
beforeEach(() => testContext.beforeEach()); // restores DB snapshot + clears Firebase
describe('MyFeature', () => {
it('should ...', async () => {
// Arrange / Act / Assert
});
});BaseIntegrationTest handles app compilation, DB seeding, snapshotting, and teardown. testContext.app is the full NestJS application instance.