与测试框架-摩卡

时间:2020-06-21 06:01:07

标签: node.js npm mocha blockchain ethereum

我正在使用以太坊平台开发简单的DApp。在这种情况下,我使用了Mocha测试框架,但会出现此错误。请帮助...

E:\ Tutorials \ Blockchain \ Practicle \ Demo> npm运行测试

demo@1.0.0测试E:\ Tutorials \ Blockchain \ Practicle \ Demo 摩卡咖啡

TypeError: Suite argument "title" must be a string. Received type "function"
    at createInvalidArgumentTypeError (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\errors.js:158:13)
    at new Suite (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\suite.js:45:15)
    at Function.Suite.create (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\suite.js:26:17)
    at Object.create (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\interfaces\common.js:128:27)
    at context.describe.context.context (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\interfaces\bdd.js:42:27)
    at Object.<anonymous> (E:\Tutorials\Blockchain\Practicle\Demo\test\inbox_test.js:13:1)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.exports.requireOrImport (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\esm-utils.js:20:12)
    at Object.exports.loadFilesAsync (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\esm-utils.js:33:34)
    at Mocha.loadFilesAsync (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\mocha.js:421:19)
    at singleRun (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\cli\run-helpers.js:156:15)
    at exports.runMocha (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\cli\run-helpers.js:225:10)
    at Object.exports.handler (E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\lib\cli\run.js:366:11)
    at E:\Tutorials\Blockchain\Practicle\Demo\node_modules\mocha\node_modules\yargs\lib\command.js:241:49
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo@1.0.0 test: `mocha`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the demo@1.0.0 test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Prabhakar's\AppData\Roaming\npm-cache\_logs\2020-06-21T05_32_41_476Z-debug.log

1 个答案:

答案 0 :(得分:-1)

我得到了答案。我正在发布它,以便对其他人有帮助...

我之前将我的describe方法定义为:

module.exports = {
    target: 'web'
}

}); Error Image

在这里,我通过了直接函数,而不是先付诸表决,这就是为什么摩卡咖啡无法做到并返回错误:

Suite参数“ title”必须为字符串。收到类型“函数”

但是在提供了我的合同方式之后,它接受了它的所有权

describe(() => {
it("can pass the test", () => {
    console.log(accounts);
});

}); Final Image