• Core
  • Connectors
  • Mock

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 { providers } from 'ethers'
 
const connector = new MockConnector({
  options: {
    signer: new providers.JsonRpcSigner(…),
  },
})

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 { providers } from 'ethers'
 
const connector = new MockConnector({
  options: {
    chainId: mainnet.id,
    signer: new providers.JsonRpcSigner(…),
  },
})

flags (optional)

Flags to simulate specific behavior of the connector.

import { MockConnector } from '@wagmi/core/connectors/mock'
import { mainnet } from '@wagmi/core/chains'
import { providers } from 'ethers'
 
const connector = new MockConnector({
  options: {
    flags: {
      failConnect: true,
    },
    signer: new providers.JsonRpcSigner(…),
  },
})
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.

signer

Signer to initialize connector with.

import { MockConnector } from '@wagmi/core/connectors/mock'
import { mainnet } from '@wagmi/core/chains'
import { providers } from 'ethers'
 
const connector = new MockConnector({
  options: {
    signer: new providers.JsonRpcSigner(…),
  },
})