1
describe("func", function () {
    let owner
    beforeEach(async function () {
      const [owner] = await ethers.getSigners()
    })
it.only("should correctly set the address", async function () {

      console.log(owner.address)
      
    })
  })

I get this error when I try to run the tests, and when I hover my mouse over 'owner' it says 'any' instead of SignerWithAddress.

TypeError: Cannot read properties of undefined (reading 'address')

1
  • 1
    Do u need “const” there? It is by the way normal JavaScript testing :)
    – Majd TL
    Commented Jul 23, 2022 at 18:07

1 Answer 1

2

You have defined local constant called owner, but haven't assigned the global owner value. Just remove the const from beforeEach action and you should have access to globally defined owner:

    beforeEach(async function () {
      [owner] = await ethers.getSigners()
    })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.