Skip to content

Commit 66b1320

Browse files
committed
test: update test case
1 parent ae0d31e commit 66b1320

File tree

16 files changed

+5360
-4571
lines changed

16 files changed

+5360
-4571
lines changed

packages/common/src/utils/__tests__/request.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ describe('request', () => {
88
expect(getWeb3AssetUrl('')).toEqual('');
99
expect(getWeb3AssetUrl('ipfs://test.com/xxxxx')).toEqual('https://ipfs.io/ipfs/test.com/xxxxx');
1010
});
11-
it('requestWeb3Asset', () => {
11+
it('requestWeb3Asset', async () => {
1212
const res = { test: 'test' };
1313
mockFetch(res);
14-
expect(requestWeb3Asset('')).rejects.toThrowError('URL not set');
15-
expect(requestWeb3Asset('ipfs://test.com/xxxxx')).resolves.toMatchObject(res);
14+
await expect(requestWeb3Asset('')).rejects.toThrowError('URL not set');
15+
await expect(requestWeb3Asset('ipfs://test.com/xxxxx')).resolves.toMatchObject(res);
1616
});
1717
});

packages/icons/src/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54429,7 +54429,7 @@ exports[`Test Icons > should render all icons 567`] = `
5442954429
/>
5443054430
</g>
5443154431
<text
54432-
style="opacity: 0.51; fill: #383642; enable-background: new; font-family: 'ArialMT'; font-size: 7.4647px;"
54432+
style="opacity: 0.51; fill: #383642; enable-background: new; font-family: "ArialMT"; font-size: 7.4647px;"
5443354433
transform="matrix(0.6978 -0.7163 0.7163 0.6978 769.3947 557.0723)"
5443454434
>
5443554435
CatCoinBSC

packages/ton/src/ton-provider/__tests__/sdk.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ describe('TonSDK', () => {
3939
);
4040
};
4141

42-
expect(errorThrowingFunctionWithUrl()).rejects.toThrow();
42+
await expect(errorThrowingFunctionWithUrl()).rejects.toThrow();
4343
const balance = await connector.getBalance();
4444
expect(balance).toBe(0n);
4545
});

packages/wagmi/src/wagmi-provider/__tests__/siwe.test.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { MetaMask } from '../../wallets';
1010
import { AntDesignWeb3ConfigProvider } from '../config-provider';
1111

1212
let locationSpy: ReturnType<typeof vi.spyOn> = undefined as any;
13-
const createMessage = vi.fn(() => 'message');
13+
const mockSignMessageAsync = vi.fn(async () => '0x123456789');
1414

1515
vi.mock('wagmi', async (importOriginal) => {
1616
const actual = await importOriginal<typeof Wagmi>();
@@ -27,7 +27,7 @@ vi.mock('wagmi', async (importOriginal) => {
2727
address: '0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B',
2828
};
2929
},
30-
useSignMessage: () => ({ signMessageAsync: createMessage }),
30+
useSignMessage: () => ({ signMessageAsync: mockSignMessageAsync }),
3131
};
3232
});
3333

@@ -43,6 +43,7 @@ describe('Wagmi siwe sign', () => {
4343
});
4444

4545
const getNonce = vi.fn(async () => '1');
46+
const createMessage = vi.fn(() => 'message');
4647
const verifyMessage = vi.fn(async () => true);
4748

4849
const config = createConfig({
@@ -75,7 +76,7 @@ describe('Wagmi siwe sign', () => {
7576
'Sign: 0x21CD...Fd3B',
7677
);
7778

78-
fireEvent.click(baseElement.querySelector('.ant-web3-connect-button')!);
79+
fireEvent.click(baseElement.querySelector('.ant-btn-compact-first-item')!);
7980

8081
await waitFor(() => {
8182
expect(getNonce).toBeCalled();
@@ -96,6 +97,7 @@ describe('Wagmi siwe sign', () => {
9697
const { createConfig, http } = await import('wagmi');
9798

9899
const getNonce = vi.fn(async () => '1');
100+
const createMessage = vi.fn(() => 'message');
99101
const verifyMessage = vi.fn(async () => true);
100102

101103
const config = createConfig({
@@ -134,7 +136,7 @@ describe('Wagmi siwe sign', () => {
134136
);
135137
const { baseElement } = render(<App />);
136138

137-
fireEvent.click(baseElement.querySelector('.ant-web3-connect-button')!);
139+
fireEvent.click(baseElement.querySelector('.ant-btn-compact-first-item')!);
138140

139141
await waitFor(() => {
140142
expect(createMessage).toBeCalledWith({
@@ -152,6 +154,7 @@ describe('Wagmi siwe sign', () => {
152154
const { createConfig, http } = await import('wagmi');
153155

154156
const getNonce = vi.fn(async () => '1');
157+
const createMessage = vi.fn(() => 'message');
155158
const verifyMessage = vi.fn(async () => true);
156159

157160
const config = createConfig({
@@ -190,7 +193,7 @@ describe('Wagmi siwe sign', () => {
190193
);
191194
const { baseElement } = render(<App />);
192195

193-
fireEvent.click(baseElement.querySelector('.ant-web3-connect-button')!);
196+
fireEvent.click(baseElement.querySelector('.ant-btn-compact-first-item')!);
194197

195198
await waitFor(() => {
196199
expect(createMessage).toBeCalledWith({
@@ -239,6 +242,7 @@ describe('Wagmi siwe sign', () => {
239242
const getNonce = vi.fn(() => {
240243
throw new Error('signAddress is required');
241244
});
245+
const createMessage = vi.fn(() => 'message');
242246
const verifyMessage = vi.fn(async () => true);
243247

244248
const renderText = vi.fn((defaultDom, account) => `Custom Sign: ${account.address}`);
@@ -281,6 +285,7 @@ describe('Wagmi siwe sign', () => {
281285
const { createConfig, http } = await import('wagmi');
282286

283287
const getNonce = vi.fn(async () => '1');
288+
const createMessage = vi.fn(() => 'message');
284289
const verifyMessage = vi.fn(async () => true);
285290

286291
const config = createConfig({

packages/web3/src/address/__tests__/__snapshots__/index.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`Address > display address with default format 1`] = `
44
<span
5-
class="ant-typography ant-web3-address css-dev-only-do-not-override-vrrzze css-dev-only-do-not-override-vrrzze"
5+
class="ant-typography ant-web3-address css-dev-only-do-not-override-1odpy5d css-dev-only-do-not-override-1odpy5d"
66
>
77
<span
88
aria-describedby="test-id"

packages/web3/src/browser-link/__tests__/index.test.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,12 @@ describe('BrowserLink', () => {
7777
expect(baseElement.querySelector('.anticon-link')).not.toBeNull();
7878
});
7979
it('support get chain from provider', async () => {
80-
const fn = vi.fn();
81-
try {
80+
// Test with unsupported chain (no browser.getBrowserLink)
81+
const originalConsoleError = console.error;
82+
const mockConsoleError = vi.fn();
83+
console.error = mockConsoleError;
84+
85+
expect(() => {
8286
render(
8387
<Web3ConfigProvider
8488
chain={{
@@ -89,12 +93,12 @@ describe('BrowserLink', () => {
8993
<BrowserLink address="0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B" />,
9094
</Web3ConfigProvider>,
9195
);
92-
} catch (error: any) {
93-
fn(error.message);
94-
}
95-
expect(fn).toHaveBeenCalledWith('getBrowserLink unsupported chain 42161');
96-
const fn2 = vi.fn();
97-
try {
96+
}).toThrow('getBrowserLink unsupported chain 42161');
97+
98+
console.error = originalConsoleError;
99+
100+
// Test with supported chain (override with Mainnet which has browser.getBrowserLink)
101+
expect(() => {
98102
render(
99103
<Web3ConfigProvider
100104
chain={{
@@ -105,10 +109,7 @@ describe('BrowserLink', () => {
105109
<BrowserLink address="0x21CDf0974d53a6e96eF05d7B324a9803735fFd3B" chain={Mainnet} />,
106110
</Web3ConfigProvider>,
107111
);
108-
} catch (error: any) {
109-
fn2(error.message);
110-
}
111-
expect(fn2).not.toHaveBeenCalled();
112+
}).not.toThrow();
112113
});
113114
it('support get chain icon from provider', async () => {
114115
const { baseElement, rerender } = render(

packages/web3/src/connect-button/__tests__/__snapshots__/profile-modal.test.tsx.snap

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`ProfileModal > match snapshot 1`] = `
55
<div />
66
<div>
77
<div
8-
class="ant-modal-root css-dev-only-do-not-override-vrrzze"
8+
class="ant-modal-root css-dev-only-do-not-override-1odpy5d"
99
>
1010
<div
1111
class="ant-modal-mask ant-fade-appear ant-fade-appear-start ant-fade"
@@ -16,8 +16,9 @@ exports[`ProfileModal > match snapshot 1`] = `
1616
>
1717
<div
1818
aria-modal="true"
19-
class="ant-modal css-dev-only-do-not-override-vrrzze hashId ant-web3-connect-button-profile-modal ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
19+
class="ant-modal css-dev-only-do-not-override-1odpy5d hashId ant-web3-connect-button-profile-modal ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
2020
role="dialog"
21+
style="width: fit-content;"
2122
>
2223
<div
2324
style="outline: none;"
@@ -62,13 +63,13 @@ exports[`ProfileModal > match snapshot 1`] = `
6263
style="text-align: center;"
6364
>
6465
<div
65-
class="ant-space css-dev-only-do-not-override-vrrzze ant-space-vertical ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
66+
class="ant-space css-dev-only-do-not-override-1odpy5d ant-space-vertical ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
6667
>
6768
<div
6869
class="ant-space-item"
6970
>
7071
<span
71-
class="ant-avatar ant-avatar-circle ant-avatar-image css-dev-only-do-not-override-vrrzze"
72+
class="ant-avatar ant-avatar-circle ant-avatar-image css-dev-only-do-not-override-1odpy5d"
7273
>
7374
<img
7475
src="https://mdn.alipayobjects.com/huamei_mutawc/afts/img/A*9jfLS41kn00AAAAAAAAAAAAADlrGAQ/original"
@@ -88,7 +89,7 @@ exports[`ProfileModal > match snapshot 1`] = `
8889
class="ant-space-item"
8990
>
9091
<span
91-
class="ant-typography ant-typography-secondary ant-web3-address css-dev-only-do-not-override-vrrzze css-dev-only-do-not-override-vrrzze"
92+
class="ant-typography ant-typography-secondary ant-web3-address css-dev-only-do-not-override-1odpy5d css-dev-only-do-not-override-1odpy5d"
9293
>
9394
<span
9495
aria-describedby="test-id"
@@ -106,15 +107,15 @@ exports[`ProfileModal > match snapshot 1`] = `
106107
class="ant-web3-connect-button-profile-modal-footer hashId"
107108
>
108109
<button
109-
class="ant-btn css-dev-only-do-not-override-vrrzze ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
110+
class="ant-btn css-dev-only-do-not-override-1odpy5d ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
110111
type="button"
111112
>
112113
<span>
113114
Copy Address
114115
</span>
115116
</button>
116117
<button
117-
class="ant-btn css-dev-only-do-not-override-vrrzze ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
118+
class="ant-btn css-dev-only-do-not-override-1odpy5d ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
118119
type="button"
119120
>
120121
<span>
@@ -141,7 +142,7 @@ exports[`ProfileModal > match snapshot without name 1`] = `
141142
<div />
142143
<div>
143144
<div
144-
class="ant-modal-root css-dev-only-do-not-override-vrrzze"
145+
class="ant-modal-root css-dev-only-do-not-override-1odpy5d"
145146
>
146147
<div
147148
class="ant-modal-mask ant-fade-appear ant-fade-appear-start ant-fade"
@@ -152,8 +153,9 @@ exports[`ProfileModal > match snapshot without name 1`] = `
152153
>
153154
<div
154155
aria-modal="true"
155-
class="ant-modal css-dev-only-do-not-override-vrrzze hashId ant-web3-connect-button-profile-modal ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
156+
class="ant-modal css-dev-only-do-not-override-1odpy5d hashId ant-web3-connect-button-profile-modal ant-zoom-appear ant-zoom-appear-prepare ant-zoom"
156157
role="dialog"
158+
style="width: fit-content;"
157159
>
158160
<div
159161
style="outline: none;"
@@ -198,13 +200,13 @@ exports[`ProfileModal > match snapshot without name 1`] = `
198200
style="text-align: center;"
199201
>
200202
<div
201-
class="ant-space css-dev-only-do-not-override-vrrzze ant-space-vertical ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
203+
class="ant-space css-dev-only-do-not-override-1odpy5d ant-space-vertical ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
202204
>
203205
<div
204206
class="ant-space-item"
205207
>
206208
<span
207-
class="ant-avatar ant-avatar-circle ant-avatar-image css-dev-only-do-not-override-vrrzze"
209+
class="ant-avatar ant-avatar-circle ant-avatar-image css-dev-only-do-not-override-1odpy5d"
208210
>
209211
<img
210212
src="https://mdn.alipayobjects.com/huamei_mutawc/afts/img/A*9jfLS41kn00AAAAAAAAAAAAADlrGAQ/original"
@@ -215,7 +217,7 @@ exports[`ProfileModal > match snapshot without name 1`] = `
215217
class="ant-space-item"
216218
>
217219
<span
218-
class="ant-typography ant-web3-address css-dev-only-do-not-override-vrrzze css-dev-only-do-not-override-vrrzze"
220+
class="ant-typography ant-web3-address css-dev-only-do-not-override-1odpy5d css-dev-only-do-not-override-1odpy5d"
219221
>
220222
<span
221223
aria-describedby="test-id"
@@ -233,15 +235,15 @@ exports[`ProfileModal > match snapshot without name 1`] = `
233235
class="ant-web3-connect-button-profile-modal-footer hashId"
234236
>
235237
<button
236-
class="ant-btn css-dev-only-do-not-override-vrrzze ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
238+
class="ant-btn css-dev-only-do-not-override-1odpy5d ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
237239
type="button"
238240
>
239241
<span>
240242
Copy Address
241243
</span>
242244
</button>
243245
<button
244-
class="ant-btn css-dev-only-do-not-override-vrrzze ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
246+
class="ant-btn css-dev-only-do-not-override-1odpy5d ant-btn-default ant-btn-color-default ant-btn-variant-outlined"
245247
type="button"
246248
>
247249
<span>

packages/web3/src/connect-button/__tests__/__snapshots__/tooltip.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`ConnectButton > should display formatted by custom formatter when pass
55
<div>
66
<button
77
aria-describedby="test-id"
8-
class="ant-btn css-dev-only-do-not-override-vrrzze ant-btn-default ant-btn-color-default ant-btn-variant-outlined ant-web3-connect-button css-dev-only-do-not-override-vrrzze ant-tooltip-open"
8+
class="ant-btn css-dev-only-do-not-override-1odpy5d ant-btn-default ant-btn-color-default ant-btn-variant-outlined ant-web3-connect-button css-dev-only-do-not-override-1odpy5d ant-tooltip-open"
99
type="button"
1010
>
1111
<div
@@ -18,7 +18,7 @@ exports[`ConnectButton > should display formatted by custom formatter when pass
1818
class="ant-web3-connect-button-text"
1919
>
2020
<span
21-
class="ant-typography ant-web3-address css-dev-only-do-not-override-vrrzze css-dev-only-do-not-override-vrrzze"
21+
class="ant-typography ant-web3-address css-dev-only-do-not-override-1odpy5d css-dev-only-do-not-override-1odpy5d"
2222
>
2323
<span
2424
aria-describedby="test-id"
@@ -33,7 +33,7 @@ exports[`ConnectButton > should display formatted by custom formatter when pass
3333
</div>
3434
<div>
3535
<div
36-
class="ant-tooltip ant-zoom-big-fast-appear ant-zoom-big-fast-appear-prepare ant-zoom-big-fast ant-web3-connect-button-tooltip css-dev-only-do-not-override-vrrzze css-dev-only-do-not-override-vrrzze ant-tooltip-placement-top"
36+
class="ant-tooltip ant-zoom-big-fast-appear ant-zoom-big-fast-appear-prepare ant-zoom-big-fast ant-web3-connect-button-tooltip css-dev-only-do-not-override-1odpy5d css-dev-only-do-not-override-1odpy5d ant-tooltip-placement-top"
3737
style="--arrow-x: 0px; --arrow-y: 0px; left: -1000vw; top: -1000vh; right: auto; bottom: auto; box-sizing: border-box;"
3838
>
3939
<div

packages/web3/src/connect-button/__tests__/tooltip.test.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ describe('ConnectButton', () => {
120120
);
121121
expect(baseElement.querySelector('.anticon-copy')).not.toBeNull();
122122
fireEvent.click(baseElement.querySelector('.anticon-copy')!);
123-
await vi.waitFor(() => {
123+
await vi.waitFor(async () => {
124124
expect(baseElement.querySelector('.ant-message')).not.toBeNull();
125125
expect(baseElement.querySelector('.ant-message-notice-content')?.textContent).toBe('Copied!');
126-
expect(readCopyText()).resolves.toBe('0x3ea2cfd153b8d8505097b81c87c11f5d05097c18');
126+
await expect(readCopyText()).resolves.toBe('0x3ea2cfd153b8d8505097b81c87c11f5d05097c18');
127127
});
128128
});
129129

@@ -137,12 +137,12 @@ describe('ConnectButton', () => {
137137
);
138138
expect(baseElement.querySelector('.anticon-copy')).not.toBeNull();
139139
fireEvent.click(baseElement.querySelector('.anticon-copy')!);
140-
await vi.waitFor(() => {
140+
await vi.waitFor(async () => {
141141
expect(baseElement.querySelector('.ant-message')).not.toBeNull();
142142
expect(baseElement.querySelector('.ant-message-notice-content')?.textContent?.trim()).toBe(
143143
'Copied!',
144144
);
145-
expect(readCopyText()).resolves.toBe('aaaaaabbbbbbcccccc');
145+
await expect(readCopyText()).resolves.toBe('aaaaaabbbbbbcccccc');
146146
});
147147
});
148148
it('should display formatted when pass format into tooltip', async () => {
@@ -160,12 +160,12 @@ describe('ConnectButton', () => {
160160
).toBe('0x 3ea2 cfd1 53b8 d850 5097 b81c 87c1 1f5d 0509 7c18');
161161
expect(baseElement.querySelector('.anticon-copy')).not.toBeNull();
162162
fireEvent.click(baseElement.querySelector('.anticon-copy')!);
163-
await vi.waitFor(() => {
163+
await vi.waitFor(async () => {
164164
expect(baseElement.querySelector('.ant-message')).not.toBeNull();
165165
expect(baseElement.querySelector('.ant-message-notice-content')?.textContent?.trim()).toBe(
166166
'Copied!',
167167
);
168-
expect(readCopyText()).resolves.toBe('0x3ea2cfd153b8d8505097b81c87c11f5d05097c18');
168+
await expect(readCopyText()).resolves.toBe('0x3ea2cfd153b8d8505097b81c87c11f5d05097c18');
169169
});
170170
});
171171
it('should display formatted by custom formatter when pass format into tooltip', async () => {

0 commit comments

Comments
 (0)