• React
  • Connectors
  • Mock

Mock

The MockConnector is a mocked Connector implementation useful for things like testing.

import { MockConnector } from 'wagmi/connectors/mock'

Usage

import { MockConnector } from 'wagmi/connectors/mock'
 
const connector = new MockConnector()

Configuration

chains (optional)

Chains supported by app. Defaults to defaultChains.

import { MockConnector } from 'wagmi/connectors/mock'
import { mainnet, optimism } from 'wagmi/chains'
 
const connector = new MockConnector({
  chains: [mainnet, optimism],
})

options

Options for configuring the connector.

import { MockConnector } from 'wagmi/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/connectors/mock'
import { mainnet } from 'wagmi/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/connectors/mock'
import { mainnet } from 'wagmi/chains'
import { createWalletClient } from 'viem'
 
const connector = new MockConnector({
  options: {
    flags: {
      failConnect: true,
    },
    walletClient: createWalletClient(…),
  },
})
NameTypeDescription
isAuthorizedbooleanTurns on authorized status to connector allowing autoconnect behavior to work.
failConnectbooleanThrows an error when attempting to connect.
failSwitchChainbooleanThrows an error when attempting to switch chains.
noSwitchChainbooleanDisables the ability to switch chains.

walletClient

Wallet Client to initialize connector with.

import { MockConnector } from 'wagmi/connectors/mock'
import { mainnet } from 'wagmi/chains'
import { createWalletClient } from 'viem'
 
const connector = new MockConnector({
  options: {
    walletClient: createWalletClient(…),
  },
})