1

I'm trying to write tests on my locomotive.js application, literally copy/pasting code from some examples on the internet. Even so, whenever I run my tests, I get an error saying

TypeError: string is not a function

When I check the number of arguments expected by locomotive.boot (using locomotive.boot.length), it says 2... But in every single example online (go ahead, google it) the documentation seems to say 3. Does anyone know what I'm doing wrong?

Here's my code:

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);
    });
});
1
  • The source code shows two parameters. That's usually the easiest thing to check. It appears you should omit your __dirname+"/.." from your call. Apr 5, 2014 at 5:14

1 Answer 1

1

There are 2 branches on the LocomotiveJS repo: - 0.3.x (https://github.com/jaredhanson/locomotive/tree/0.3.x) - master (https://github.com/jaredhanson/locomotive/tree/master)

If you're using version 0.3.x your code should work, the function declaration actually shows 4 arguments: dir, env, options, callback you can have a look at the function definition here (Locomotive.prototype.boot): 0.3.x/lib/locomotive/index.js

As of version 0.4.x (branch master) the boot function only accepts 2 arguments: env, callback the function definition for this branch is here (Application.prototype.boot): master/lib/application.js

so your code should look something like:

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

Hope this helps.

1
  • How does it know the directory which needed to be passed in before? My app is starting but don't think it's registering any routes
    – Matt Kim
    Aug 11, 2014 at 17:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.