0.2.1 ā€¢ Published 2 years ago

jest-web3 v0.2.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Jest Web3 - Web3 Environemnt for Jest

Jest Testing Environemnt w/ Ganache Instance and Ethers Provider interface

Install

šŸ“¦ jest-web3@0.1.0

yarn add -D jest-web3

Add to your Jest config.

{
  "testEnvironment": "ethers",
  "testEnvironmentOptions": {
      "port": "8545",
      "mnemonic": ""
      ...moreOptions // view options section
  }
}

Options

Ganache Instance

You can specify options for the ganache Instance by following the interface:

 export interface IProviderOptions {
      account_keys_path?: string;
      accounts?: object[];
      allowUnlimitedContractSize?: boolean;
      blockTime?: number;
      db_path?: string;
      debug?: boolean;
      default_balance_ether?: number;
      fork?: string | object;
      fork_block_number?: string | number;
      forkCacheSize?: number;
      gasLimit?: string | number;
      gasPrice?: string;
      hardfork?: "berlin" | "london" | "arrowGlacier"; // arrowGlacier not yet!
      hd_path?: string;
      locked?: boolean;
      logger?: {
        log(msg: string): void;
      };
      mnemonic?: string;
      network_id?: number;
      networkId?: number;
      port?: number;
      seed?: any;
      time?: Date;
      total_accounts?: number;
      unlocked_accounts?: string[];
      verbose?: boolean;
      vmErrorsOnRPCResponse?: boolean;
      ws?: boolean;
}

Usage

Use Ethereum blockchain with an injected Ethers Provider/Ethers compatible Provider in your tests:

test('accounts', async () => {
    const unlockedAccounts = ethersProvider.getAccounts();

    expect(unlockedAccounts.length).toBe(10);
});

License

MIT