Skip to content

Commit 00c4f27

Browse files
committed
fix tests
1 parent 1ad187b commit 00c4f27

File tree

2 files changed

+1
-110
lines changed

2 files changed

+1
-110
lines changed

packages/thirdweb/src/react/core/hooks/wallets/useAutoConnectCore.test.tsx

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { renderHook, waitFor } from "@testing-library/react";
22
import type { ReactNode } from "react";
3-
import { describe, expect, it, vi } from "vitest";
3+
import { describe, expect, it } from "vitest";
44
import { MockStorage } from "~test/mocks/storage.js";
55
import { TEST_CLIENT } from "~test/test-clients.js";
66
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
@@ -98,60 +98,4 @@ describe("useAutoConnectCore", () => {
9898
{ timeout: 1000 },
9999
);
100100
});
101-
102-
it("should call onTimeout on ... timeout", async () => {
103-
const wallet = createWalletAdapter({
104-
adaptedAccount: TEST_ACCOUNT_A,
105-
client: TEST_CLIENT,
106-
chain: ethereum,
107-
onDisconnect: () => {},
108-
switchChain: () => {},
109-
});
110-
mockStorage.setItem("thirdweb:active-wallet-id", wallet.id);
111-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
112-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
113-
// Purposefully mock the wallet.autoConnect method to test the timeout logic
114-
wallet.autoConnect = () =>
115-
new Promise((resolve) => {
116-
setTimeout(() => {
117-
// @ts-ignore Mock purpose
118-
resolve("Connection successful");
119-
}, 2100);
120-
});
121-
renderHook(
122-
() =>
123-
useAutoConnectCore(
124-
mockStorage,
125-
{
126-
wallets: [wallet],
127-
client: TEST_CLIENT,
128-
onTimeout: () => {},
129-
timeout: 0,
130-
},
131-
(id: WalletId) =>
132-
createWalletAdapter({
133-
adaptedAccount: TEST_ACCOUNT_A,
134-
client: TEST_CLIENT,
135-
chain: ethereum,
136-
onDisconnect: () => {
137-
console.warn(id);
138-
},
139-
switchChain: () => {},
140-
}),
141-
),
142-
{ wrapper },
143-
);
144-
await waitFor(
145-
() => {
146-
expect(warnSpy).toHaveBeenCalled();
147-
expect(warnSpy).toHaveBeenCalledWith(
148-
"AutoConnect timeout: 0ms limit exceeded.",
149-
);
150-
expect(infoSpy).toHaveBeenCalled();
151-
expect(infoSpy).toHaveBeenCalledWith("TIMEOUTTED");
152-
warnSpy.mockRestore();
153-
},
154-
{ timeout: 2000 },
155-
);
156-
});
157101
});

packages/thirdweb/src/wallets/connection/autoConnectCore.test.ts

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -90,59 +90,6 @@ describe("useAutoConnectCore", () => {
9090
).toBe(false);
9191
});
9292

93-
it("should call onTimeout on ... timeout", async () => {
94-
vi.mocked(getUrlToken).mockReturnValue({});
95-
96-
const wallet = createWalletAdapter({
97-
adaptedAccount: TEST_ACCOUNT_A,
98-
client: TEST_CLIENT,
99-
chain: ethereum,
100-
onDisconnect: () => {},
101-
switchChain: () => {},
102-
});
103-
mockStorage.setItem("thirdweb:active-wallet-id", wallet.id);
104-
const warnSpy = vi.spyOn(console, "warn").mockImplementation(() => {});
105-
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
106-
// Purposefully mock the wallet.autoConnect method to test the timeout logic
107-
wallet.autoConnect = () =>
108-
new Promise((resolve) => {
109-
setTimeout(() => {
110-
// @ts-ignore Mock purpose
111-
resolve("Connection successful");
112-
}, 2100);
113-
});
114-
115-
await autoConnectCore({
116-
force: true,
117-
storage: mockStorage,
118-
props: {
119-
wallets: [wallet],
120-
client: TEST_CLIENT,
121-
onTimeout: () => {},
122-
timeout: 0,
123-
},
124-
createWalletFn: (id: WalletId) =>
125-
createWalletAdapter({
126-
adaptedAccount: TEST_ACCOUNT_A,
127-
client: TEST_CLIENT,
128-
chain: ethereum,
129-
onDisconnect: () => {
130-
console.warn(id);
131-
},
132-
switchChain: () => {},
133-
}),
134-
manager,
135-
});
136-
137-
expect(warnSpy).toHaveBeenCalled();
138-
expect(warnSpy).toHaveBeenCalledWith(
139-
"AutoConnect timeout: 0ms limit exceeded.",
140-
);
141-
expect(infoSpy).toHaveBeenCalled();
142-
expect(infoSpy).toHaveBeenCalledWith("TIMEOUTTED");
143-
warnSpy.mockRestore();
144-
});
145-
14693
it("should handle auth cookie storage correctly", async () => {
14794
const mockAuthCookie = "mock-auth-cookie";
14895
const wallet = createWalletAdapter({

0 commit comments

Comments
 (0)