I have a test file in hardhat like so:
const { expect } = require("chai");
describe("contract tests", function () {
it("does function one", async function () {
expect(await someContract.someFunc()).to.equal(something);
});
it("does function two", async function () {
expect(await someContract.someOtherFunction()).to.equal(somethingOtherThing);
});
});
How can I test just one of the its
at a time?
In mocha you can run a single test with the --grep
command. Is there something similar for hardhat?
Something like:
npx hardhat test --grep "does function one"
or
npx hardhat test --grep "does function two"
Best Answer
Use
.only()
. For example, your test file would look like this:and then you can run
npx hardhat test
and it will only run that test set.If you just want one
it
, instead of using.only()
ondescribe
, you can useit.only()
.EDIT:
As of hardhat version 2.9, you can use
--grep
as described in the original question.