PatrickAlphaC / hardhat-fund-me-fcc

82 stars 184 forks source link

Error! While testing Fund Function #37

Closed ChiragG2101 closed 2 years ago

ChiragG2101 commented 2 years ago

ERROR:

1) FundMe
       fund
         Fails if you don't send enough ETH:
     AssertionError: Expected transaction to be reverted with You need to spend more ETH, but other exception was thrown: Error: VM Exception while processing transaction: reverted with reason string 'Didn't send enough!

Here's the code i m using to test Fund Function

const { deployments, ethers, getNamedAccounts } = require("hardhat")
const { assert,expect } = require("chai")

describe("FundMe", async function() {
    let fundMe
    let deployer
    let mockV3Aggregator
    beforeEach(async function() {
        // const accounts = await ethers.getSigners()
        // const accountZero = accounts(0)
        deployer = (await getNamedAccounts()).deployer
        await deployments.fixture("all")
        fundMe = await ethers.getContract("FundMe", deployer)
        mockV3Aggregator = await ethers.getContract("MockV3Aggregator",deployer )
    })
    describe("constructor", async function() {
        it("sets the aggregator addresses correctly", async function() {
            const response = await fundMe.priceFeed()
            assert.equal(response, mockV3Aggregator.address)
        })
    })

    describe("fund",async function(){
        it("Fails if you don't send enough ETH", async function(){
            await expect(fundMe.fund()).to.be.revertedWith(
                "You need to spend more ETH"
            )
        })
    })
})
RoboCrypter commented 2 years ago

Hello there: You need to replace this line of code: await expect(fundMe.fund()).to.be.revertedWith("You need to spend more ETH") with await expect(fundMe.fund()).to.be.reverted Hopefully...It will work

ChiragG2101 commented 2 years ago

Thanks! it worked