Angular testing with Karma: “module is not defined”

前端 未结 2 1998
闹比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 16:59

    This is not the answer to your particular issue, but I had a similar symptom in a very similar scenario. However, the root cause was different, so I'll share it here in case others find this post and they have the same issue I had.

    In my case, because I introduced tests later in the game, there was a mismatch between the versions of angular (1.4.7) and angular-mocks (1.6.9).

    I found out this was the root cause by using the debug of Karma in the browser. Lowering the version of angular-mocks to match angular solved the issue.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题