为什么我会得到“错误:分辨率方法超标”?
升级后,摩卡甚至不能运行简单的testing,这里是代码
const assert = require('assert'); it('should complete this test', function (done) { return new Promise(function (resolve) { assert.ok(true); resolve(); }) .then(done); });
我从这里拿这个代码
我明白它现在抛出一个exceptionError: Resolution method is overspecified. Specify a callback * or * return a Promise; not both.
Error: Resolution method is overspecified. Specify a callback * or * return a Promise; not both.
但如何使其工作? 我不明白。 我有
node -v 6.9.4 mocha -v 3.2.0
如何运行这个代码现在是一个新的和正确的格式?
放下
.then(done);
并用function(done)
replacefunction(done)
function()
你正在返回一个Promise,所以调用done是多余的,就像它在错误信息中所说的那样
在老版本中,如果使用asynchronous方法,则必须使用callback
it ('returns async', function(done) { callAsync() .then(function(result) { assert.ok(result); done(); }); })
现在你有一个select返回一个承诺
it ('returns async', function() { return new Promise(function (resolve) { callAsync() .then(function(result) { assert.ok(result); resolve(); }); }); })
但是使用两者都是误导性的(参见https://github.com/mochajs/mocha/issues/2407 )
摩卡允许使用callback:
it('should complete this test', function (done) { new Promise(function (resolve) { assert.ok(true); resolve(); }) .then(done); });
或者返回一个承诺:
it('should complete this test', function () { return new Promise(function (resolve) { assert.ok(true); resolve(); }); });
你不能这样做。
- 使用mocha和node.js对私有函数进行unit testing
- 使用Gulp,Mocha,Browserify进行正确configuration,以执行服务器端testing的客户端testing
- 用mochatestingasynchronous函数
- 如何防止摩卡离开状态为1的过程
- 摩卡testing与inheritance的JavaScript
- 运行node.js mochatesting时意外的令牌ILLEGAL
- mocha节点检查器不能使用“debugging器”命令
- 如何通过Passport / Facebook战略authenticationSupertest请求/?
- 在Mocha&Sinon的NodeJS中testing诺言callback