mardi 3 mai 2016

Karma, Jasmine Unit Testing for AngularJS

I am trying to launch a spec file to test a controller that belongs to the project I am currently working on. Basically I have been going through several obstacles to launch the test. The last error I am getting is the following:

"Uncaught ReferenceError: require is not defined"

// Karma configuration

module.exports = function(config) { config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: http://ift.tt/1ft83uu
frameworks: ['browserify', 'jasmine'],


// list of files / patterns to load in the browser
files: [

    //Libs

     I put my libraries here

    //Source

    All The files involved were put right here

    //Tests
    'test/unit/user/*.spec.js'

],


plugins: [

    "karma-browserify",
    "karma-chrome-launcher",
    "karma-jasmine"

],

// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: http://ift.tt/1gyw6MG
preprocessors: {
    'test/unit/user/*.spec.js': [ 'browserify' ]
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: http://ift.tt/1ft83KQ
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: http://ift.tt/1ft83KU
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,

// Concurrency level
// how many browser should be started simultaneous
concurrency: Infinity

}) };

This is the controller I meant to test

angular.module('mod.users', ['srv.mod.user', 'mod.utils', 'mod.user', 'mod.messagges', 'srv.backend', 'srv.mod.sharedData', 'srv.mod.base'])

.controller('UsersCtrl', function ($scope, $state, $stateParams, userService, loggedUserService, $log, $uibModal, baseService, $filter) {

    var initDropDown = function() {

       $scope.something = otherthings
       $scope.userFilter = otherthings

       baseService.getGenericDropdown(...)
          .then(function(result))

       $scope.$watchCollection(){

       }

    }

    $scope.init = function(){

    // Other things

    }

}

.directive("mod.users", function(){
    return{
         restrict: 'E',
         controller: 'UsersCtrl',
         templateUrl: './resources/templates/user/users.html'

});

Also, How would you test a controller and a directive with these structures ? Thanks in advance.. This is driving me crazy...

Aucun commentaire:

Enregistrer un commentaire