test: clarify discord matrix assertions

This commit is contained in:
Peter Steinberger
2026-05-08 13:48:05 +01:00
parent 7e26b59f13
commit d3b47526bc
5 changed files with 15 additions and 16 deletions

View File

@@ -484,15 +484,15 @@ describe("GatewayPlugin", () => {
expect(gateway.ws).toBeNull();
expect(gateway.firstHeartbeatTimeout).toBeUndefined();
expect(gateway.heartbeatInterval).toBeUndefined();
expect(() => vi.advanceTimersByTime(20)).not.toThrow();
vi.advanceTimersByTime(20);
expect(send).not.toHaveBeenCalled();
expect(() =>
expect(
(
gateway as unknown as {
sendHeartbeat(): void;
}
).sendHeartbeat(),
).not.toThrow();
).toBeUndefined();
});
it("clears stale heartbeat timers before early reconnect exits", () => {

View File

@@ -327,9 +327,9 @@ describe("monitorDiscordProvider", () => {
expect(monitorLifecycleMock).not.toHaveBeenCalled();
expect(disconnect).toHaveBeenCalledTimes(1);
expect(() =>
expect(
emitter.emit("error", new Error("Max reconnect attempts (0) reached after code 1005")),
).not.toThrow();
).toBe(true);
expect(runtime.error).toHaveBeenCalledWith(
expect.stringContaining("suppressed late gateway reconnect-exhausted error after dispose"),
);

View File

@@ -412,7 +412,7 @@ describe("DiscordVoiceManager", () => {
expectConnectedStatus(manager, "1002");
});
it("does not throw when stale tracked voice connections are already destroyed", async () => {
it("skips destroying stale tracked voice connections that are already destroyed", async () => {
const staleConnection = createConnectionMock();
staleConnection.state.status = "destroyed";
staleConnection.destroy.mockImplementation(() => {
@@ -429,7 +429,7 @@ describe("DiscordVoiceManager", () => {
expect(staleConnection.destroy).not.toHaveBeenCalled();
});
it("does not throw when leaving an already destroyed voice connection", async () => {
it("skips destroying an already destroyed voice connection on leave", async () => {
const connection = createConnectionMock();
connection.destroy.mockImplementation(() => {
throw new Error("Cannot destroy VoiceConnection - it has already been destroyed");
@@ -1095,7 +1095,7 @@ describe("DiscordVoiceManager", () => {
expect(agentCommandMock).toHaveBeenCalledTimes(1);
});
it("DiscordVoiceReadyListener: propagates autoJoin errors fire-and-forget without throwing", async () => {
it("DiscordVoiceReadyListener: starts autoJoin fire-and-forget on ready", async () => {
const manager = createManager();
const autoJoinSpy = vi
.spyOn(manager, "autoJoin")
@@ -1104,7 +1104,7 @@ describe("DiscordVoiceManager", () => {
const { DiscordVoiceReadyListener } = managerModule;
const listener = new DiscordVoiceReadyListener(manager);
await expect(listener.handle(undefined, undefined as never)).resolves.not.toThrow();
await expect(listener.handle(undefined, undefined as never)).resolves.toBeUndefined();
expect(autoJoinSpy).toHaveBeenCalledTimes(1);
});
@@ -1115,7 +1115,7 @@ describe("DiscordVoiceManager", () => {
const { DiscordVoiceResumedListener } = managerModule;
const listener = new DiscordVoiceResumedListener(manager);
await expect(listener.handle(undefined, undefined as never)).resolves.not.toThrow();
await expect(listener.handle(undefined, undefined as never)).resolves.toBeUndefined();
expect(autoJoinSpy).toHaveBeenCalledTimes(1);
});
});

View File

@@ -228,7 +228,7 @@ describe("resolveMentions", () => {
});
it("ignores out-of-range hexadecimal HTML entities in visible labels", () => {
expect(() =>
expect(
resolveMentions({
content: {
msgtype: "m.text",
@@ -239,11 +239,11 @@ describe("resolveMentions", () => {
text: "hello",
mentionRegexes: [],
}),
).not.toThrow();
).toEqual({ hasExplicitMention: false, wasMentioned: false });
});
it("ignores oversized decimal HTML entities in visible labels", () => {
expect(() =>
expect(
resolveMentions({
content: {
msgtype: "m.text",
@@ -255,7 +255,7 @@ describe("resolveMentions", () => {
text: "hello",
mentionRegexes: [],
}),
).not.toThrow();
).toEqual({ hasExplicitMention: false, wasMentioned: false });
});
it("does not detect mention when displayName is spoofed", () => {

View File

@@ -1573,8 +1573,7 @@ describe("MatrixClient crypto bootstrapping", () => {
}
).cryptoBootstrapper.bootstrap = bootstrapSpy;
// start() must NOT throw even when the repair bootstrap fails
await expect(client.start()).resolves.not.toThrow();
await expect(client.start()).resolves.toBeUndefined();
// repair was attempted
expect(bootstrapSpy).toHaveBeenCalledTimes(2);