Skip to content

Commit 7309b6c

Browse files
committed
fix: fix failed test
1 parent 43eaecd commit 7309b6c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/api/providers/__tests__/vscode-lm.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ describe("VsCodeLmHandler", () => {
8989

9090
beforeEach(() => {
9191
vi.clearAllMocks()
92+
// Set up a default successful mock for selectChatModels before creating the handler
93+
const mockModel = { ...mockLanguageModelChat }
94+
;(vscode.lm.selectChatModels as Mock).mockResolvedValue([mockModel])
9295
handler = new VsCodeLmHandler(defaultOptions)
9396
})
9497

@@ -733,13 +736,13 @@ describe("VsCodeLmHandler", () => {
733736

734737
it("should throw a Zoo Code branded error when client initialization fails", async () => {
735738
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
736-
// Use mockRejectedValue (not Once) because beforeEach already called selectChatModels once
737739
;(vscode.lm.selectChatModels as Mock).mockRejectedValue(new Error("select failed"))
738740
handler["client"] = null
739741

740-
await expect(handler.initializeClient()).rejects.toThrow(
741-
"Zoo Code <Language Model API>: Failed to initialize client:",
742-
)
742+
// Catch the unhandled rejection that may occur from the constructor's async call
743+
const initPromise = handler.initializeClient()
744+
745+
await expect(initPromise).rejects.toThrow("Zoo Code <Language Model API>: Failed to initialize client:")
743746

744747
expect(consoleErrorSpy).toHaveBeenCalledWith(
745748
"Zoo Code <Language Model API>: Client initialization failed:",

0 commit comments

Comments
 (0)