无法读取未定义的属性(读取

发布于 2025-02-05 07:52:40 字数 505 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀念你的温柔 2025-02-12 07:52:40

const assert = require(“ assert”);

为什么要导入名称值?那是导致问题的原因

const assert = require("assert");

Why import a name value? That's whats causing the issue

ㄖ落Θ余辉 2025-02-12 07:52:40

sustert被默认导出(module.exports = function assert(){...})导出,因此您需要相应地导入它。

const assert = require('assert');

assert gets exported with a default export (module.exports = function assert() {...}) so you need to import it accordingly.

const assert = require('assert');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文