English 中文(简体)
2. 测试剂量,以明示方式――再处理
原标题:testing node.js with expresso - redis session store

我在尝试用诺德.js语学习TDD。 我认为,由于再保护者,我只指挥了hang。 以<代码>ctrl+C对这一过程进行杀 最后,产出一米(通过100%3次测试)。

导致<代码>expresso的 我可以做些什么?

我期待着:

// Module dependencies.

var auth = require( connect-auth ),
    RedisStore = require( connect-redis );


var express = require( express );
var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
  app.set( views , __dirname +  /views );
  app.set( view engine ,  jade );
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser());
  app.use(express.session({ store: new RedisStore, secret: "secret goes here" }));
  app.use(app.router);
  app.use(express.static(__dirname +  /public ));
});

app.configure( development , function(){
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
});

app.configure( production , function(){
  app.use(express.errorHandler()); 
});

// Routes

app.get( / , function(req, res){
  res.render( index , {
    title:  Orchestrate 
  });
});

app.get( /login , function(req, res){
  res.render( user/login , {
    title:  Login 
  });
});

app.get( /register , function(req, res){
  res.render( user/login , {
    title:  Register 
  });
});

// Only listen on $ node app.js

if (!module.parent) {
  app.listen(3000);
  console.log("Express server listening on port %d", app.address().port);
}

我的测试:

// Run $ expresso

/**
 * Module dependencies.
 */

var app = require( ../app ),
    assert = require( assert );


module.exports = {
   GET / : function(){
    assert.response(app,
      { url:  /  },
      { status: 200, headers: {  Content-Type :  text/html; charset=utf-8  }},
      function(res){
        assert.includes(res.body,  <title>Orchestrate</title> );
      });
  },
   GET /login : function(){
    assert.response(app,
      { url:  /login  },
      { status: 200, headers: {  Content-Type :  text/html; charset=utf-8  }},
      function(res){
        assert.includes(res.body,  <title>Login</title> );
      });
  },
   GET /register : function(){
    assert.response(app,
      { url:  /register  },
      { status: 200, headers: {  Content-Type :  text/html; charset=utf-8  }},
      function(res){
        assert.includes(res.body,  <title>Register</title> );
      });
  }

iii

最佳回答

如果所有测试都完成,请写你这样的测试,测试操作员应终止:

   GET / : function(done){
    assert.response(app,
      { url:  /  },
      { status: 200, headers: {  Content-Type :  text/html; charset=utf-8  }},
      function(res){
        assert.includes(res.body,  <title>Orchestrate</title> );

        done();
      });
问题回答

The answer is that Mongoose doesn t close the connections itself nicely, which causes issues when using expresso.

你们需要增加“mongoose.dislink()”,例如: 最后,我总是补充说:

    tearDown: function(done){
       mongoose.disconnect();
       done();
    }

希望会有所帮助。

问题是,该断言是按时间顺序印制的。 你的测试并不是因为连接而放弃的,他们只是不知道你通过的所有试验。

同一问题

mongoose.connect();

明示测试只要不与 d挂钩就终止,否则就需要杀 process,看看结果。

对于今后遭受这一问题打击的人,与称为





相关问题
Separating rapid development from refactoring/optimization

I m working in a team of 2 front-end developers on a web-based late-stage startup project. The site works quite well, but there s a lot of room for improvement code-wise, as the code is quite messy ...

Test-driven development with ASP.NET MVC - where to begin?

I ve read a lot about Test-Driven Development (TDD) and I find the principles very compelling, based on personal experience. At the moment I m developing a website for a start-up project I m involved ...

Silencing Factory Girl logging

Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot s factory girl in my specs, every time ...

TDD vs. Unit testing [closed]

My company is fairly new to unit testing our code. I ve been reading about TDD and unit testing for some time and am convinced of their value. I ve attempted to convince our team that TDD is worth ...

unit test a method that creates an object

I m trying to get my head round Unit Testing and there s one more piece of the jigsaw I need to find. What I m trying to do is write tests for the following code. In this case, I ve got a really ...

Testing private method of an abstract class using Reflection

How can I test a private method of an abstract class using reflection (using C#)? I am specifically interested in adapting the code found in this thread. I am aware of the discussion around the ...

C#: How would you unit test GetHashCode?

Testing the Equals method is pretty much straight forward (as far as I know). But how on earth do you test the GetHashCode method?

热门标签