1
0
Fork 0
blog/src/features/Web3/hooks/useSend/send.test.ts

37 lines
1001 B
TypeScript
Raw Normal View History

2023-11-05 21:11:13 +01:00
import { test, expect, vi } from 'vitest'
import { send } from './send'
import * as wagmiActionsMock from '../../../../../test/__mocks__/wagmi/actions'
test('with undefined params', async () => {
2024-03-13 02:20:29 +01:00
const result = await send(
undefined as any,
undefined as any,
undefined as any,
undefined as any,
undefined as any
)
2023-11-05 21:11:13 +01:00
expect(result).toBeUndefined()
})
test('with isNative true uses correct method', async () => {
const selectedToken = {
address: '0x0',
decimals: 18
2024-03-13 02:20:29 +01:00
} as any
2023-11-05 21:11:13 +01:00
const spy = vi.spyOn(wagmiActionsMock, 'sendTransaction')
2024-03-13 02:20:29 +01:00
await send({} as any, selectedToken, '1', '0xabcdef1234567890', 1)
2023-11-05 21:11:13 +01:00
expect(spy).toHaveBeenCalledOnce()
})
test('with isNative false uses correct method', async () => {
const selectedToken = {
address: '0xabcdef1234567890',
decimals: 18
2024-03-13 02:20:29 +01:00
} as any
2023-11-05 21:11:13 +01:00
const spy = vi.spyOn(wagmiActionsMock, 'writeContract')
2024-03-13 02:20:29 +01:00
await send({} as any, selectedToken, '1', '0xabcdef1234567890', 1)
2023-11-05 21:11:13 +01:00
expect(spy).toHaveBeenCalledOnce()
})