당신은 기본적으로 스스로를 프로그램 할 수 있습니다 :
var EXPECTED_TIMEOUT = 2000; // This value should be lesser than the actual mocha test timeout.
it('passport.socketio should never let it connect', function(done) {
this.timeout(EXPECTED_TIMEOUT + 100); // You add this to make sure mocha test timeout will only happen as a fail-over, when either of the functions haven't called done callback.
var timeout = setTimeout(done, EXPECTED_TIMEOUT); // This will call done when timeout is reached.
socket.on('connect', function() {
clearTimeout(timeout);
// this should never happen, is the expected behavior.
done(new Error('Unexpected call'));
});
});
또한 코드 단축
addTimeout 모듈을 사용할 수 있습니다
:
var EXPECTED_TIMEOUT = 2000; // This value should be lesser than the actual mocha test timeout.
it('passport.socketio should never let it connect', function(done) {
this.timeout(EXPECTED_TIMEOUT + 100); // You add this to make sure mocha test timeout will only happen as a fail-over, when either of the functions haven't called done callback.
function connectCallback() {
done(new Error('Unexpected Call'));
}
socket.on('connect', addTimeout(EXPECTED_TIMEOUT, connectCallback, function() {
done()
});
});
을