摩卡正确运行,但显示未定义
我使用mocha
来testing我的nodejs代码,testing运行正常,但是当我使用mocha test.js
来运行testing时,似乎我传递给describe
的string不显示。
代码如下:
var assert = require("should"); describe("FrontEndTest", function(){ describe('websocket establish connection', function(){ it('should establish connection correctly', function(done){ var res; var wsClient = create_ws_client('ws://127.0.0.1:9876','brain_burst'); wsClient.on('connect', function(connection){ res = true; res.should.be.true; done(); }); wsClient.on('connectFailed', function(error){ res = false; res.should.be.true; done(); }); console.log(res); }); it('should disconnected by server.(also, that may crash server if there is not a protocol validation)', function(done){ var res; var wsClient = create_ws_client('ws://127.0.0.1:9876'); wsClient.on('connect', function(connection){ res = true; res.should.be.false; done(); }); wsClient.on('connectFailed', function(error){ res = false; res.should.be.false; done(); }); }); }); });
mocha
指令的结果显示:
undefined ..
✔完成2个testing(68毫秒)
为什么它显示undefined
因为我已经传递一个string?
是不是下面的线导致它?
console.log(res);