1

我正在尝试在我的 locomotive.js 应用程序上编写测试,从互联网上的一些示例中复制/粘贴代码。即便如此,每当我运行测试时,我都会收到一条错误消息

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);
    });
});
4

1 回答 1

1

LocomotiveJS repo 上有 2 个分支: - 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,回调这个分支的函数定义在这里(Application.prototype.boot):master/lib/application.js

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

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

希望这可以帮助。

于 2014-04-10T10:27:13.273 回答