Skip to content

Commit 13f12e6

Browse files
author
magne
committed
feat: add unit test for connection
1 parent 6f0a4eb commit 13f12e6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/environment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class AmqpEnvironment implements Environment {
2020
private readonly username: string
2121
private readonly password: string
2222
private readonly container: Container
23-
private connections: Connection[] = []
23+
private readonly connections: Connection[] = []
2424

2525
constructor({ host, port, username, password }: EnvironmentParams) {
2626
this.host = host
@@ -53,7 +53,7 @@ export class AmqpEnvironment implements Environment {
5353

5454
async close(): Promise<void> {
5555
await this.closeConnections()
56-
this.connections = []
56+
this.connections.length = 0
5757
}
5858

5959
private async closeConnections(): Promise<void> {

test/unit/connection.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { afterEach, beforeEach, describe, test } from "vitest"
2+
import { use, expect } from "chai"
3+
import chaiAsPromised from "chai-as-promised"
4+
import { createEnvironment, Environment } from "../../src/environment.js"
5+
import { host, port, username, password, numberOfConnections, eventually } from "../support/util.js"
6+
7+
use(chaiAsPromised)
8+
9+
describe("Connection", () => {
10+
let environment: Environment
11+
12+
beforeEach(async () => {
13+
environment = createEnvironment({
14+
host,
15+
port,
16+
username,
17+
password,
18+
})
19+
})
20+
21+
afterEach(async () => {
22+
await environment.close()
23+
})
24+
25+
test("closing the connection", async () => {
26+
const connection = await environment.createConnection()
27+
28+
await connection.close()
29+
30+
await eventually(async () => {
31+
expect(await numberOfConnections()).to.eql(0)
32+
})
33+
})
34+
})

0 commit comments

Comments
 (0)