Mock
The MockConnector
is a mocked Connector
implementation useful for things like testing.
import { MockConnector } from '@wagmi/core/connectors/mock'
Usage
import { MockConnector } from '@wagmi/core/connectors/mock'
const connector = new MockConnector()
Configuration
chains (optional)
Chains supported by app. Defaults to defaultChains
.
import { MockConnector } from '@wagmi/core/connectors/mock'
import { mainnet, optimism } from '@wagmi/core/chains'
const connector = new MockConnector({
chains: [mainnet, optimism],
})
options
Options for configuring the connector.
import { MockConnector } from '@wagmi/core/connectors/mock'
import { createWalletClient } from 'viem'
const connector = new MockConnector({
options: {
walletClient: createWalletClient(…),
},
})
chainId (optional)
Chain ID to use for the connector. Defaults to first chain in chains
.
import { MockConnector } from '@wagmi/core/connectors/mock'
import { mainnet } from '@wagmi/core/chains'
import { createWalletClient } from 'viem'
const connector = new MockConnector({
options: {
chainId: mainnet.id,
walletClient: createWalletClient(…),
},
})
flags (optional)
Flags to simulate specific behavior of the connector.
import { MockConnector } from '@wagmi/core/connectors/mock'
import { mainnet } from '@wagmi/core/chains'
import { createWalletClient } from 'viem'
const connector = new MockConnector({
options: {
flags: {
failConnect: true,
},
walletClient: createWalletClient(…),
},
})
Name | Type | Description |
---|---|---|
isAuthorized | boolean | Turns on authorized status to connector allowing autoconnect behavior to work. |
failConnect | boolean | Throws an error when attempting to connect. |
failSwitchChain | boolean | Throws an error when attempting to switch chains. |
noSwitchChain | boolean | Disables the ability to switch chains. |
walletClient
Wallet Client to initialize connector with.
import { MockConnector } from '@wagmi/core/connectors/mock'
import { mainnet } from '@wagmi/core/chains'
import { createWalletClient } from 'viem'
const connector = new MockConnector({
options: {
walletClient: createWalletClient(…),
},
})