Following the instructions,
I put this in hardhat.config.ts
:
import '@nomicfoundation/hardhat-chai-matchers';
In my test I have:
expect(maxCount).to.equal(64);
where maxCount
is a BigNumber from ethers.js, and 64
is a regular Javascript/Typescript number.... but I get this error:
AssertionError: expected [ BigNumber { value: "64" } ] to equal 64
... which means that the hardhat chai matcher is not kicking in, as it is supposed to handle the BigNumber by performing the conversion automatically as part of the assertion.
This leads me to think that the way I'm importing this module may be incorrect. What's the proper way?
Technically, the "Usage" section
of the docs state it as a CommonJS require
:
require("@nomicfoundation/hardhat-chai-matchers");
Since my hardhat config (and rest of project) is in Typescript, I've used this instead:
import '@nomicfoundation/hardhat-chai-matchers';
More details:
Here're my dev dependencies from package.json
:
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "1.0.6",
"@nomicfoundation/hardhat-toolbox": "2.0.2",
"@types/chai": "4.3.4",
"@types/fs-extra": "11.0.1",
"@types/mocha": "10.0.1",
"@types/node": "18.14.6",
"fs-extra": "11.1.0",
"hardhat": "2.13.0",
"ts-node": "10.9.1",
"typescript": "4.9.5"
}
And here're my run times:
$ node -v
v16.13.1
$ npm -v
8.1.2
Edit
In an attempt to debug, I've manually edited
node_modules/@nomicfoundation/hardhat-chai-matchers/src/internal/bigNumber.ts
to add console.log
statements in a couple of spots.
function overwriteBigNumberFunction(
functionName: Methods,
readableName: string,
readableNegativeName: string,
_super: (...args: any[]) => any,
chaiUtils: Chai.ChaiUtils
) {
console.log('hh chai matcher overwriteBigNumberFunction');
/* ... */
} else if (isBigNumber(expectedFlag) || isBigNumber(actualArg)) {
console.log('hh chai matcher bignit');
/* ... */
Then subsequently run npx hardhat console
.
Neither of the above log statements are output,
leading me further to believe that the way I'm importing isn't right.