Skip to content

Instantly share code, notes, and snippets.

@PaulRBerg
Created July 29, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulRBerg/0a8b4806898d81685719d7f7a26afff0 to your computer and use it in GitHub Desktop.
Save PaulRBerg/0a8b4806898d81685719d7f7a26afff0 to your computer and use it in GitHub Desktop.
Augmenting the Context type used by Mocha in beforeEach, it, etc.
import { Erc20 } from "../typechain/Erc20";
declare module "mocha" {
export interface Context {
token: Token;
}
}
import { deployContract } from "ethereum-waffle";
import Erc20Artifact from "../../artifacts/Erc20.json";
import { Erc20 } from "../../typechain/Erc20";
describe("Token", function () {
beforeEach(async function() {
const decimals: number = 18;
const name: string = "My Token";
const symbol: string = "TKN";
this.token = (await deployContract(deployer, Erc20Artifact, [name, symbol, decimals])) as Erc20;
});
it("should test something", async function() {
// this.token has auto-completion here!
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment