jest-environment-ethereum

1.1.1 • Public • Published

jest-environment-ethereum · npm version

Run your tests using Jest under clean Ethereum blockchain powered by Ganache.

Install

Install dependencies.

npm install --save-dev jest-environment-ethereum [web3 or ethers]

Add to your Jest config.

{
  "testEnvironment": "ethereum",
  "testEnvironmentOptions": {
      "injectWeb3Provider": true
  }
}

Usage

Use Ethereum blockchain with injected provider in your tests:

test('transfer balance', async () => {
    const unlockedAccounts = web3.eth.getAccounts();
    const newAccount = web3.eth.accounts.create();

    await web3.eth.sendTransaction({
      from: unlockedAccounts[0],
      to: newAccount.address,
      value: '1000000000000000000'
    })

    expect(web3.eth.getBalance(newAccount.address)).toBe('1000000000000000000');
});

Options

injectWeb3Provider

If true, inject a Web3 provider connected to test Ethereum blockchain as global.web3.

injectEthersProvider

If true, inject a Ethers.js provider connected to test Ethereum blockchain as global.ethersProvider.

Package Sidebar

Install

npm i jest-environment-ethereum

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

9.66 kB

Total Files

6

Last publish

Collaborators

  • tnayuki