I am using Mocha and Chai for writing tests for a smart contract deployed on the development blockchain with truffle.
I have a contract named Election
which contains two candidates.
The test code is as follows:
it("Checking the properties for candidates", () => {
return Election.deployed().then((app) => {
return [app.candidates(1), app];
}).then(params => {
const [candidate1, app] = params;
assert.equal(candidate1.id, 0);
return [app.candidates(1), app];
}).then(params => {
const [candidate2, app] = params;
assert.equal(candidate2.id, 1);
});
});
The test cases pass when I am not using the array destructuring to return app.candidates()
and an instance of the app
. In that case I had to declare a global variable, assign it to app
and use it in every scope. But I want to avoid defining a global variable. I came across this post on SO which suggests using ES6 destructuring.
But here I am getting candidate1.id
and candidate2.id
both as undefined
.
What am I doing wrong here?