feeloor
feeloor

Reputation: 45

Backbone, Marionette, Grunt, jasmine-testing

I'm currently trying to develop my first Backbone Marionette application, I'm also using Grunt Task runner as well as Jasmine for testing.

So I've created my own Model for login, and I want to use it in my tests but somehow I can't get it to work, I keep getting the error that it's undefined...

For the simplicity I've pasted my code on Pastebin: Login Model: http://pastebin.com/BGfpkNXC Structure: https://i.sstatic.net/qx6N9.jpg

Grunt-jasmine

jasmine: {
        all: {
            src: 'app/js/modules/{,*/}*.js',
            options: {
                vendor: [
                    'app/lib/jquery/dist/jquery.js',
                    'app/lib/underscore/underscore.js',
                    'app/lib/backbone/backbone.js',
                    'app/lib/marionette/lib/core/backbone.marionette.js',
                    'app/lib/backbone.babysitter/lib/backbone.babysitter.js',
                    'app/lib/backbone.wreqr/lib/backbone.wreqr.js',
                    'app/lib/bootstrap/dist/js/bootstrap.js',
                    'app/lib/leaflet/dist/leaflet.js'
                ],
                specs: 'app/js/test/**/*.js'
            }
        }
    }

Login.spec.js

describe('Login', function () {
  it('Login - Create Auth', function () {
      var App = new Backbone.Marionette.Application();
      var Auth = App.Auth;

    expect(typeof Auth).toMatch('object');
  });
});

Hope I've supplied all info needed.

Thanks in advance. Feeloor

Upvotes: 0

Views: 122

Answers (1)

feeloor
feeloor

Reputation: 45

I got it working by installing the grunt-template-jasmine-requirejs package, as well as changing my grunt to:

jasmine: {
        all: {
            src: 'modules/**/*/*.js',
            options: {
                specs: 'app/js/test/**/*.js',
                template: require('grunt-template-jasmine-requirejs'),
                templateOptions: {
                    requireConfigFile: 'app/js/main.js',
                    requireConfig: {
                        baseUrl: "app/js/"
                    }
                }
            }
        }
    },

And then on every spec:

define(['modules/login/models/auth'], function(Auth) {

Hope this helps someone.

Upvotes: 1

Related Questions