I have the following TypeScript files:
foo.ts
import { shouldBehaveLikeBar } from "./bar";
describe("Foo", function() {
const wallets: Wallet[];
beforeEach(async function() {
wallets = (await ethers.getSigners()) as Wallet[];
});
shouldBehaveLikeBar(wallets);
});
bar.ts
export function shouldBehaveLikeBar(wallets: Wallet[]) {
describe("Bar", function() {
it("should test something", async function() {
const something = await callFunctionThatNeeds(wallets[0].address);
expect(something).to.equal(true);
});
});
}
Basically, I need wallets[0]
to exist in the should test something
test suite. But it doesn't, I'm getting this error:
TypeError: Cannot read property 'address' of undefined
I thought that mocha would wait for beforeEach
to execute before passing the values onto shouldBehaveLikeBar
. How can I do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…