Skip to content

Commit 3f52815

Browse files
committed
chore: add test to connection-requested
1 parent 4c357f9 commit 3f52815

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/common/connectionManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export type AnyConnectionState =
5959
| ConnectionStateErrored;
6060

6161
export interface ConnectionManagerEvents {
62+
"connection-requested": [AnyConnectionState];
6263
"connection-succeeded": [ConnectionStateConnected];
6364
"connection-timed-out": [ConnectionStateErrored];
6465
"connection-closed": [ConnectionStateDisconnected];
@@ -74,6 +75,8 @@ export class ConnectionManager extends EventEmitter<ConnectionManagerEvents> {
7475
}
7576

7677
async connect(settings: ConnectionSettings): Promise<AnyConnectionState> {
78+
this.emit("connection-requested", this.state);
79+
7780
if (this.state.tag == "connected" || this.state.tag == "connecting") {
7881
await this.disconnect();
7982
}

tests/integration/common/connectionManager.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ describeWithMongoDB("Connection Manager", (integration) => {
6262
expect(collections).not.toBe([]);
6363
});
6464

65+
it("should notify that the connection was requested", () => {
66+
expect(connectionManagerSpies["connection-requested"]).toHaveBeenCalledOnce();
67+
});
68+
6569
it("should notify that the connection was successful", () => {
6670
expect(connectionManagerSpies["connection-succeeded"]).toHaveBeenCalledOnce();
6771
});

0 commit comments

Comments
 (0)