Skip to content

Commit 2858ea0

Browse files
committed
fix test
1 parent 987936c commit 2858ea0

File tree

1 file changed

+27
-36
lines changed

1 file changed

+27
-36
lines changed

packages/xl-ai/src/api/formats/json/errorHandling.test.ts

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,43 +61,34 @@ describe.skip("Error handling", () => {
6161
],
6262
});
6363

64-
// Use a flag to track if an error was thrown
65-
let errorThrown = false;
66-
let caughtError: any = null;
67-
68-
try {
69-
const chat = new Chat<UIMessage>({
70-
sendAutomaticallyWhen: () => false,
71-
transport: new ClientSideTransport({
72-
model: testAIModels.openai,
73-
stream,
74-
_additionalOptions: {
75-
maxRetries: 0,
76-
},
77-
objectGeneration: true, // TODO: switch to text
78-
}),
79-
});
80-
const aiRequest = await buildAIRequest({
81-
editor,
82-
});
83-
await sendMessageWithAIRequest(chat, aiRequest, {
84-
role: "user",
85-
parts: [
86-
{
87-
type: "text",
88-
text: "translate to Spanish",
89-
},
90-
],
91-
});
92-
} catch (error: any) {
93-
errorThrown = true;
94-
caughtError = error;
95-
}
64+
const chat = new Chat<UIMessage>({
65+
sendAutomaticallyWhen: () => false,
66+
transport: new ClientSideTransport({
67+
model: testAIModels.openai,
68+
stream,
69+
_additionalOptions: {
70+
maxRetries: 0,
71+
},
72+
objectGeneration: true, // TODO: switch to text
73+
}),
74+
});
75+
const aiRequest = await buildAIRequest({
76+
editor,
77+
});
78+
const ret = await sendMessageWithAIRequest(chat, aiRequest, {
79+
role: "user",
80+
parts: [
81+
{
82+
type: "text",
83+
text: "translate to Spanish",
84+
},
85+
],
86+
});
9687

97-
// Assertions outside the try/catch
98-
expect(errorThrown).toBe(true);
99-
expect(caughtError).toBeDefined();
100-
expect(caughtError.message || caughtError.toString()).toContain(
88+
expect(ret.ok).toBe(true);
89+
expect(chat.status).toBe("error");
90+
expect(chat.error).toBeDefined();
91+
expect(chat.error?.message).toContain(
10192
"Rate limit exceeded, please try again later",
10293
);
10394
});

0 commit comments

Comments
 (0)