Search code examples
javascriptunit-testingsoliditychaihardhat

Error: Invalid Chai property: revertedWith on Hardhat


Currently working on hardhat using chai also

const {assert, expect} = require("chai")
const {deployments, ethers, getNamedAccounts, network} = require("hardhat")
const {developmentChains} = require("../../helper-hardhat-config")
   it("Fails if you don't send enough ETH", async function () {
            await expect(fundMe.fund()).to.be.revertedWith(
                "You need to spend more eth"
            )
        })

Thats my source code but i get this error

   FundMe
       withdraw
         is allows us to withdraw with multiple funders:
     Error: Invalid Chai property: reverted

Solution

  • According to https://stackoverflow.com/users/10262805/yilmaz who helped

    i was able to fix it by installing

    # yarn add --dev @nomicfoundation/hardhat-chai-matchers
    

    And i also added this

    require("@nomicfoundation/hardhat-chai-matchers")
    

    on my hardhat.config.js