Skip to content

Commit 779621e

Browse files
committed
fixup types in tests
1 parent f6053b0 commit 779621e

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

client/src/components/__tests__/AuthDebugger.test.tsx

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jest.mock("@/hooks/use-toast", () => ({
4141
}),
4242
}));
4343

44-
// Mock MCP SDK functions
44+
// Mock MCP SDK functions - must be before imports
4545
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
4646
auth: jest.fn(),
4747
discoverOAuthMetadata: jest.fn(),
@@ -50,14 +50,20 @@ jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
5050
exchangeAuthorization: jest.fn(),
5151
}));
5252

53-
// Import mocked functions
53+
// Import the functions to get their types
5454
import {
55-
discoverOAuthMetadata as mockDiscoverOAuthMetadata,
56-
registerClient as mockRegisterClient,
57-
startAuthorization as mockStartAuthorization,
58-
exchangeAuthorization as mockExchangeAuthorization,
55+
discoverOAuthMetadata,
56+
registerClient,
57+
startAuthorization,
58+
exchangeAuthorization,
5959
} from "@modelcontextprotocol/sdk/client/auth.js";
6060

61+
// Type the mocked functions properly
62+
const mockDiscoverOAuthMetadata = discoverOAuthMetadata as jest.MockedFunction<typeof discoverOAuthMetadata>;
63+
const mockRegisterClient = registerClient as jest.MockedFunction<typeof registerClient>;
64+
const mockStartAuthorization = startAuthorization as jest.MockedFunction<typeof startAuthorization>;
65+
const mockExchangeAuthorization = exchangeAuthorization as jest.MockedFunction<typeof exchangeAuthorization>;
66+
6167
// Mock Session Storage
6268
const sessionStorageMock = {
6369
getItem: jest.fn(),
@@ -101,22 +107,22 @@ describe("AuthDebugger", () => {
101107
beforeEach(() => {
102108
jest.clearAllMocks();
103109
sessionStorageMock.getItem.mockReturnValue(null);
104-
(mockDiscoverOAuthMetadata as jest.Mock).mockResolvedValue(
105-
mockOAuthMetadata,
106-
);
107-
(mockRegisterClient as jest.Mock).mockResolvedValue(mockOAuthClientInfo);
108-
(mockStartAuthorization as jest.Mock).mockResolvedValue({
110+
111+
// Set up mock implementations
112+
mockDiscoverOAuthMetadata.mockResolvedValue(mockOAuthMetadata);
113+
mockRegisterClient.mockResolvedValue(mockOAuthClientInfo);
114+
mockStartAuthorization.mockResolvedValue({
109115
authorizationUrl: new URL("https://oauth.example.com/authorize"),
110116
codeVerifier: "test_verifier",
111117
});
112-
(mockExchangeAuthorization as jest.Mock).mockResolvedValue(mockOAuthTokens);
118+
mockExchangeAuthorization.mockResolvedValue(mockOAuthTokens);
113119
});
114120

115-
const renderAuthDebugger = (props = {}) => {
121+
const renderAuthDebugger = (props: any = {}) => {
116122
const mergedProps = {
117123
...defaultProps,
118124
...props,
119-
authState: { ...defaultAuthState, ...props.authState },
125+
authState: { ...defaultAuthState, ...(props.authState || {}) },
120126
};
121127
return render(
122128
<TooltipProvider>
@@ -290,9 +296,7 @@ describe("AuthDebugger", () => {
290296
fireEvent.click(screen.getByText("Continue"));
291297
});
292298

293-
expect(mockDiscoverOAuthMetadata).toHaveBeenCalledWith(
294-
"https://example.com",
295-
);
299+
expect(mockDiscoverOAuthMetadata).toHaveBeenCalledWith("https://example.com");
296300
});
297301
});
298302
});

0 commit comments

Comments
 (0)