1

I use mocha to test my nodejs code, and the test runs just ok, but when I use mocha test.js to run test, it seems that the string I passed to describe does not show.

The code is as follows:

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();
            });
        });
    });
});

The result of mocha command shows:

undefined ․․

✔ 2 tests complete (68 ms)

Why it shows undefined since I already pass a string?

bxshi
  • 2,252
  • 5
  • 31
  • 50

1 Answers1

2

Isn't the following line causing it?

console.log(res);
Pickels
  • 33,902
  • 26
  • 118
  • 178
  • 1
    Yes, it is because this output which variable is not assigned to a value. Thanks, pal. – bxshi Nov 07 '12 at 14:27