Lesson 9: TypeError: Cannot read properties of undefined (reading 'checkUpkeep') at Context.<anonymous> (test\unit\Raffle.test.js:80:68) #6793
Unanswered
AaliyahBatool
asked this question in
Q&A
Replies: 1 comment
-
To fix this issue, ensure that the raffle contract is properly deployed and initialized before the test runs. Here’s how you can update your Raffle.test.js file: Updated Raffle.test.js const { ethers, deployments, getNamedAccounts, network } = require("hardhat");
const { assert } = require("chai");
describe("Raffle Unit Tests", function () {
let raffle;
let interval;
beforeEach(async () => {
// Deploy the Raffle contract
await deployments.fixture(["all"]); // Ensure all deployments are run
// Get the deployed Raffle contract instance
const RaffleDeployment = await deployments.get("Raffle");
raffle = await ethers.getContractAt(
RaffleDeployment.abi,
RaffleDeployment.address
);
// Get the interval from the contract
interval = await raffle.getInterval();
});
describe("checkUpkeep", function () {
it("returns false if people haven't sent any ETH", async () => {
// Fast-forward time to exceed the interval
await network.provider.send("evm_increaseTime", [Number(interval) + 1]);
await network.provider.request({ method: "evm_mine", params: [] });
// Call checkUpkeep and check the result
const { upkeepNeeded } = await raffle.callStatic.checkUpkeep("0x"); // upkeepNeeded = (timePassed && isOpen && hasBalance && hasPlayers);
assert(!upkeepNeeded);
});
});
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am getting this error when i run "yarn hardhat test" :
1) Raffle Unit Tests
checkUpkeep
returns false if people haven't sent any ETH:
TypeError: Cannot read properties of undefined (reading 'checkUpkeep')
at Context. (test\unit\Raffle.test.js:80:68)
Here is my Raffle.test.js :
describe("checkUpkeep", function () {
it("returns false if people haven't sent any ETH", async () => {
await network.provider.send("evm_increaseTime", [Number(interval) + 1]);
await network.provider.request({ method: "evm_mine", params: [] });
const { upkeepNeeded } = await raffle.callStatic.checkUpkeep("0x"); // upkeepNeeded = (timePassed && isOpen && hasBalance && hasPlayers);
assert(!upkeepNeeded);
})
Beta Was this translation helpful? Give feedback.
All reactions