dimanche 3 avril 2016

Reference Error: module is not defined at object in Unit testing

I am getting this error Module is not defined. I tried to find the answer but not able to get.

Here is my code:

in custom filter file : filter.js

angular.module('usp').filter('dateFormat', function () {
     return function (input) {
         return moment(input).format("MMM-DD-YYYY");
     };
 });

in unit test case filter file: fliter.spec.js

describe('filter', function() {

    var $filter;

    beforeEach(function () {
       module('usp');
    });

    beforeEach(inject(function(_$filter_){
        $filter = _$filter_;
    }));

    it('should format the date in this format MMM-DD-YYYY', function() {
        var length = $filter('dateFormat');//dateFormat filter name
        expect(dateFormat("13-10-2016")).toEqual("10-13-2016");
      });
});

in gulp file : gulpfile.js

gulp.task('test', function (done) {
    new Server({
        configFile: __dirname + '/karma.conf.js',
        files: ['test/common/filters/filter.spec.js'],
        singleRun: true
    }, function () {
        done();
    }).start();
});

in config file : karma.conf.js

module.exports = function (config) {
    config.set({
        basePath: '',
        frameworks: ['jasmine'],
        files: [
            {
                pattern: 'src/static/js/common/filters/filter.js',
                watched: false
            },
            /* Tests */
            {
                pattern: 'src/static/libs/angularjs/core/angular-1.4.1/angular-mocks.js',
                watched: false
            },
    ],
        exclude: [
    ],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Chrome'              
              ],
        singleRun: false
    })
}

Please tell me where I am going wrong, I am not able to get....

Aucun commentaire:

Enregistrer un commentaire