Skip to content

Commit

Permalink
test: add afterAll hook for cleaning up test context
Browse files Browse the repository at this point in the history
  • Loading branch information
typeWolffo committed Aug 9, 2024
1 parent 27a5ec2 commit f76c219
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 4 additions & 0 deletions apps/api/src/auth/__tests__/auth.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ describe("AuthService", () => {
emailAdapter.clearEmails();
});

afterAll(async () => {
await testContext.teardown();
});

describe("register", () => {
it("should register a new user successfully", async () => {
const user = userFactory.build();
Expand Down
6 changes: 2 additions & 4 deletions apps/api/test/create-unit-test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Provider } from "@nestjs/common";
import { Test, TestingModule } from "@nestjs/testing";
import { EmailAdapter } from "src/common/emails/adapters/email.adapter";
import { StartedTestContainer } from "testcontainers";
import { AppModule } from "../src/app.module";
import { DatabasePg } from "../src/common";
import { closeTestDatabase, setupTestDatabase } from "./test-database";
import { EmailAdapter } from "src/common/emails/adapters/email.adapter";
import { EmailTestingAdapter } from "./helpers/test-email.adapter";
import { setupTestDatabase } from "./test-database";

export interface TestContext {
module: TestingModule;
Expand Down Expand Up @@ -33,8 +33,6 @@ export async function createUnitTest(
if (container) {
await container.stop();
}
await module.close();
await closeTestDatabase();
};

return {
Expand Down

0 comments on commit f76c219

Please sign in to comment.