mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 21:04:45 +00:00
test: guard discord listener mock calls
This commit is contained in:
@@ -14,6 +14,15 @@ function createLogger() {
|
||||
};
|
||||
}
|
||||
|
||||
function firstErrorMessage(logger: ReturnType<typeof createLogger>): string {
|
||||
const firstCall = logger.error.mock.calls.at(0);
|
||||
if (!firstCall) {
|
||||
throw new Error("expected logger.error call");
|
||||
}
|
||||
expect(firstCall).toHaveLength(1);
|
||||
return String(firstCall[0]);
|
||||
}
|
||||
|
||||
function fakeEvent(channelId: string) {
|
||||
return { channel_id: channelId } as never;
|
||||
}
|
||||
@@ -136,10 +145,7 @@ describe("DiscordMessageListener", () => {
|
||||
await expect(listener.handle(fakeEvent("ch-1"), {} as never)).resolves.toBeUndefined();
|
||||
await flushAsyncWork();
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
expect(logger.error.mock.calls[0]).toHaveLength(1);
|
||||
expect(String(logger.error.mock.calls[0]?.[0])).toContain(
|
||||
"discord handler failed: Error: boom",
|
||||
);
|
||||
expect(firstErrorMessage(logger)).toContain("discord handler failed: Error: boom");
|
||||
});
|
||||
|
||||
it("calls onEvent callback for each message", async () => {
|
||||
@@ -185,8 +191,7 @@ describe("DiscordInteractionListener", () => {
|
||||
await flushAsyncWork();
|
||||
|
||||
expect(logger.error).toHaveBeenCalledTimes(1);
|
||||
expect(logger.error.mock.calls[0]).toHaveLength(1);
|
||||
expect(String(logger.error.mock.calls[0]?.[0])).toContain(
|
||||
expect(firstErrorMessage(logger)).toContain(
|
||||
"discord interaction handler failed: Error: interaction boom",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user