无法读取未定义的属性(读取
TypeError:无法读取未定义的属性(读取“相等”),也无法在松露控制台中读取候选人的数量时也是不确定的。命令(.candidatesCount()。tonumber)有什么problme吗?
const { assert } = require("assert");
var Election = artifacts.require("./Election.sol");
contract("Election", function (acc) {
it("initializes with two candidates", function () {
return Election.deployed()
.then(function (ins) {
return ins.candidatesCount();
})
.then(function (count) {
assert.equal(count, 2);
});
});
});
TypeError: Cannot read properties of undefined (reading 'equal') and also in truffle console when i try to see the number of candidates it is also undefined. is there any problme with the command (.candidatesCount().toNumber)?
const { assert } = require("assert");
var Election = artifacts.require("./Election.sol");
contract("Election", function (acc) {
it("initializes with two candidates", function () {
return Election.deployed()
.then(function (ins) {
return ins.candidatesCount();
})
.then(function (count) {
assert.equal(count, 2);
});
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
const assert = require(“ assert”);
为什么要导入名称值?那是导致问题的原因
const assert = require("assert");
Why import a name value? That's whats causing the issue
sustert
被默认导出(module.exports = function assert(){...}
)导出,因此您需要相应地导入它。assert
gets exported with a default export (module.exports = function assert() {...}
) so you need to import it accordingly.