Locomotive.js在调用“locomotive.boot”时抛出错误

我试图在我的locomotive.js应用程序上编写testing,从字面上从互联网上的一些例子复制/粘贴代码。 即使如此,每当我运行我的testing,我得到一个错误说

TypeError: string is not a function 

当我检查locomotive.boot(使用locomotive.boot.length)期望的参数的数量,它说2 …但在每一个在线的例子(继续,谷歌它)的文档似乎说3.有谁知道我做错了什么?

这是我的代码:

 var locomotive = require('locomotive'), should = require('should'), request = require('supertest'); var app, server; describe('Application', function() { before(function(done) { locomotive.boot( __dirname+"/..", "test", function(err, express) { if (err) throw err; app = this; express.listen(4000, '0.0.0.0', function() { var addr = this.address(); console.log('Server started. [Env: '+SOPS.conf.get('app:environment')+'] [Addr: '+addr.address+'] [Port: '+addr.port+']'); done(); }); server = express; }); }); it('should have started the app', function(){ should.exist(app); should.exist(express); }); }); 

LocomotiveJS回购有两个分支: – 0.3.x( https://github.com/jaredhanson/locomotive/tree/0.3.x ) – master( https://github.com/jaredhanson/locomotive/tree/master

如果你使用的是0.3.x版本,你的代码应该可以工作,函数声明实际上显示了4个参数:dir,env,options,callback你可以看看这里的函数定义(Locomotive.prototype.boot):0.3.x /lib/locomotive/index.js

从版本0.4.x(分支主机)开始,函数只接受2个参数:env,callback这个分支的函数定义在这里(Application.prototype.boot):master / lib / application.js

所以你的代码应该是这样的:

 locomotive.boot( "test", *yourcallback* ); 

希望这可以帮助。