-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
should use 'self.currentRunnable' or 'self.test' instead of 'test'? #189
Conversation
nope it should be fine as-is, currentRunnable may be the hooks as well |
var http = require('http');
var should = require('should');
var connect = require('connect');
var RedisStore = require('connect-redis')(connect);
var app = connect.createServer();
app.use(connect.cookieParser());
app.use(connect.session({
secret : 'secret is this',
store : new RedisStore() //if use RedisStore, "TypeError: Cannot set property 'passed' of undefined" will apear
}))
app.use("/testPath", function(req, res){
setTimeout(function(){
res.end('{"status":"ok"}');
res.setHeader('Content-Type', 'application/json');
}, 200);
})
describe('connect test', function(){
before(function(){
app.listen(3000);
})
describe('#get', function(){
it('should get hello', function(done){
var opt = {
host : 'localhost',
port : 3000,
path : '/testPath'
}
http.get(opt, function(res){
var bufs = [];
res.on('data', function(data){
bufs.push(data);
})
res.on('end', function(data){
bufs.push(data||'');
bufs.join().toString().should.include('ok');
done();
})
})
})
})
}) When I test this, this error happened, I use connect 1.8.5 & connect-redis 1.2.0. I don't kown where the problem is, but it happened. If remove the RedisStore, it will be fine. |
i dont get that error, but this is incorrect: app.use("/testPath", function(req, res){
setTimeout(function(){
res.end('{"status":"ok"}');
res.setHeader('Content-Type', 'application/json');
}, 200); you cant set header fields after responding, it should be: app.use("/testPath", function(req, res){
setTimeout(function(){
res.setHeader('Content-Type', 'application/json');
res.end('{"status":"ok"}');
}, 200);
}) app.use("/testPath", function(req, res){
setTimeout(function(){
res.send({ status: 'ok' })
}, 200);
}) |
I kown,i did this on purpose, Dont fix this error and run the test, If this error throwed here, I got Error like this: ./node_modules/mocha/bin/mocha --reporter spec test.js connect test ✖ 2 of 1 tests failed:
In my own real code, I made this kind of mistake not obvious, then I test with mocha , this error made me puzzled. |
weiiird i didnt get that i'll try again |
|
oh wait now i got it with a few tweaks |
this is a similar yet shitty problem that we face:
however in practice I find this comes up extremely rare
|
i sort of understand. when an error throwed after done(), some strange error will happened. Especially in async test, like this
I got this...
So weiiird. But I must avoid this kind of stupid error appear in my program. |
should use 'self.currentRunnable' or 'self.test' instead of 'test'? I'm not sure use which one, but 'test' may be covered when the callback function is called.