我正在尝试使用 CoffeeScript 学习 node 和 Express 3。我正在使用 Mocha 进行测试并尝试引用端口号:
describe "authentication", ->
describe "GET /login", ->
body = null
before (done) ->
options =
uri: "http://localhost:#{app.get('port')}/login"
request options, (err, response, _body) ->
body = _body
done()
it "has title", ->
assert.hasTag body, '//head/title', 'Demo app - Login'
我正在使用它,因为它也是 app.js 文件中使用的内容:
require('coffee-script');
var express = require('express')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options',{layout:false});
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
app.locals.pretty = true;
});
app.configure('test', function(){
app.set('port', 3001);
});
require('./apps/authentication/routes')(app)
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});
但是,当我运行此测试时,出现错误:
TypeError: Object #<Object> has no method 'get'
有人可以解释为什么它在测试中不起作用以及我可以做些什么作为替代方案?