mardi 28 avril 2015

Karma RequireJS AngularJS

I'm trying to get Karma, RequireJS, AngularJS to play together but am having difficulty. The code is currently structured as follows:

app.js:

define('sapp', ['main', 'jquery', ...],

    function(main, $, ....) {

            var app = angular.module("myApp", [...]);


            ctrl = app.controller('myController', function($scope, $http, $resource, $timeout) {
                  ...
            });



            app.config(function($interpolateProvider, $httpProvider) {
                $interpolateProvider.startSymbol('{[');
                $interpolateProvider.endSymbol(']}');
                $httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
            });

            angular.bootstrap(document, ["myApp"]);


        return {app: app, ctrl: ctrl};
});


require(['common'], function(common){
    require(['sapp'], function(wrapper){
        console.log(wrapper);
        window.wrapper = wrapper
    });
});

app.spec.js

define( ['app'], function (appModule){

   require(['sapp'], function(wrapper){
        console.log(wrapper);
   });

    console.log(appModule)

   describe('AppController controller', function () {
        it('should initialize controller properties', function () {
            expect(true).toBe(true);
        });
    });
});

I'm not sure how to get access to the app, and the controllers so that I can test them. I thought that perhaps wrapping them in a require block would do it but that doesn't seem to work.

At present the output from running app.spec.js just logs 'undefined' for console.log(appModule), and the console.log(wrapper) line never seems to be run.

Any Ideas?

Aucun commentaire:

Enregistrer un commentaire