Socket
Socket
Sign inDemoInstall

jest-environment-hardhat

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-environment-hardhat

A jest environment with hardhat built in


Version published
Weekly downloads
848
increased by23.8%
Maintainers
1
Weekly downloads
 
Created
Source

jest-environment-hardhat

npm Tests Lint

A jest environment with hardhat built in.

jest-environment-hardhat is a drop-in jest environment for running hardhat inline with your tests. Instead of running a separate hardhat node, this environment runs a node and exposes a global Hardhat interface to interact with it.

Installation

First, install jest-environment-hardhat and its dependencies using yarn.

The environment needs @nomiclabs/hardhat-ethers, ethers, and hardhat installed to run. These are installed as peer dependencies to ensure that you retain control over versioning.

yarn add -D @nomiclabs/hardhat-ethers ethers hardhat
yarn add -D jest-environment-hardhat

Then, use the runner either using a doc-comment, or using jest configuration. See the jest documentation for more.

jest-environment-hardhat extends a node environment by default. A jsdom environment is also available, using jest-environment-hardhat/dist/jsdom.

Using a doc-comment

Files starting with a @jest-environment preamble use the specified runner:

/**
 * @jest-environment jest-environment-hardhat
 */

Using jest configuration

You may also configure your test environment through the jest.config.js file, using the testEnvironment property.

  "testEnvironment": "jest-environment-hardhat",

Subclassing your own runner

jest-environment-hardhat exports a node and jsdom environment. If you'd like to extend your own environment, you can use the setup function exported by jest-environment-hardhat/setup. See src/node.ts for an example.

Documentation

Using the environment will expose hardhat on the global scope, which you can use to interact with the hardhat network in your tests.

For documentation on the hardhat global, see the type definitions.

For examples of how to interact with the hardhat network, see the tests.

Typescript

If you are using Typescript, you can import types by adding import jest-environment-hardat to your test file, or by adding jest-environment-hardhat types to your tsconfig.


Made with 🦄 by Uniswap Labs

FAQs

Package last updated on 31 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc