Lesson 9- Error in running unit test #2226
Answered
by
othaime-en
narendra-sajwani
asked this question in
Q&A
-
While running unit test for constructor, following error is coming: const { assert } = require("chai")
const { network, getNamedAccounts, deployments, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper-hardhat-config")
!developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Unit Tests", async function () {
let raffle, vrfCoordinatorV2Mock
const chainId = network.config.chainId
beforeEach(async function () {
const deployer = await getNamedAccounts()
await deployments.fixture(["all"])
raffle = await ethers.getContract("Raffle", deployer)
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
})
describe("constructor", async function () {
it("Initializes the raffle correctly", async function () {
// Ideally, we make our tests have only 1 assert per "it"
const raffleState = await raffle.getRaffleState()
const interval = await raffle.getInterval()
assert.equal(raffleState.toString(), "0")
assert.equal(interval.toString(), networkConfig[chainId][interval])
})
})
}) Can someone help on this? Edit: Figured out where I made mistake, the working code is below: const { assert } = require("chai")
const { network, getNamedAccounts, deployments, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../../helper-hardhat-config")
!developmentChains.includes(network.name)
? describe.skip
: describe("Raffle Unit Tests", async function () {
let raffle, vrfCoordinatorV2Mock
const chainId = network.config.chainId
beforeEach(async function () {
const { deployer } = await getNamedAccounts()
await deployments.fixture(["all"])
raffle = await ethers.getContract("Raffle", deployer)
vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock", deployer)
})
describe("constructor", async function () {
it("Initializes the raffle correctly", async function () {
// Ideally, we make our tests have only 1 assert per "it"
const raffleState = await raffle.getRaffleState()
const interval = await raffle.getInterval()
assert.equal(raffleState.toString(), "0")
assert.equal(interval.toString(), networkConfig[chainId]["interval"])
})
})
}) Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
othaime-en
Aug 31, 2022
Replies: 1 comment 2 replies
-
enclose deployer in curly braces |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
narendra-sajwani
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
enclose deployer in curly braces
{}
Rewrite the line
const deployer = await getNamedAccounts()
asconst {deployer} = await getNamedAccounts()
because you are extracting deployer which is an object fromgetNamedAccounts