1

I have a few test files:

./test/ContractA.test.js

const { expect } = require("chai");

describe("ContractA tests", function () {
  it("does function one", async function () {
    expect(await contractA.someFunc()).to.equal(something);
  });
  it("does function two", async function () {
    expect(await contractA.someOtherFunction()).to.equal(somethingOtherThing);
  });
});

./test/ContractB.test.js

const { expect } = require("chai");

describe("ContractB tests", function () {
  it("does function one", async function () {
    expect(await contractB.someFunc()).to.equal(something);
  });
  it("does function two", async function () {
    expect(await contractB.someOtherFunction()).to.equal(somethingOtherThing);
  });
});

When I run hardhat test all the files run.

How Can I run all the tests in ContractA.test.js?


Things I've Already Tried

hardhat test ./test/ContratA.test.js - this does not run any tests at all...

hardhat test --grep "ContractA" - also does not run any tests...

2 Answers 2

0

yes you can do that. You just need to put ".only" after that describe, that you want to run. In your case:

const { expect } = require("chai");

describe.only("ContractA tests", function () {   it("does function one", async function () {
    expect(await contractA.someFunc()).to.equal(something);   });   it("does function two", async function () {
    expect(await contractA.someOtherFunction()).to.equal(somethingOtherThing);   }); });
3
  • This answer is incorrect. When I add .only all my other test files are still run.
    – Jim
    Aug 6 at 5:07
  • Explaining once again: In my above answer, ".only" is to be used for single test case file which have more than one describe. Only that describe will work, which have .only in front of it. For different test case files you have to comment other ones, which you don't want to test. Aug 8 at 5:01
  • This "answer" does not address my question at all. Please try again!
    – Jim
    Aug 9 at 15:01
0
$ yarn hardhat test ./test/ContratA.test.js

Should work as the command line helper message explains:

$ yarn hardhat test --help

    Usage: hardhat [GLOBAL OPTIONS] test [--bail] [--deploy-fixture] [--grep <STRING>] [--no-compile] [--no-impersonation] [--parallel] [...testFiles]
    POSITIONAL ARGUMENTS:
    
      testFiles     An optional list of files to test (default: [])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.