1.1.1 • Published 3 years ago

jest-environment-ethereum v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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.

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.3.0

3 years ago