Angular testing with Karma: “module is not defined”

前端 未结 2 2015
闹比i
闹比i 2020-12-28 16:17

I know this question has been asked many times, and I know that in most cases people are missing the angular-mocks.js file.

I\'m running into the same i

2条回答
  •  余生分开走
    2020-12-28 17:13

    The message stating that module/angular is not defined means that your angular-mocks.js file is not being loaded, despite the fact you have it listed in your karma.conf.js file.

    The problem you're experiencing is gulp-karma ignoring your karma.conf.js files array. This happens when you pass a string or glob into gulp.src in the gulpfile.

    To work around this, pass gulp.src a string for a bogus file, "./foobar" for instance, and this will cause the files array in the karma.conf.js file to be used instead.

    gulp.task('test', function () {
      gulp.src('./foobar')
        .pipe(karma({
          configFile: 'karma.conf.js',
          action: 'run'
        }));
    });
    

    Hope this helps!

    Reference: https://github.com/lazd/gulp-karma/issues/9

提交回复
热议问题