$ injector:nomod与业力+茉莉花

时间:2018-09-12 13:22:37

标签: angularjs jasmine karma-jasmine karma-runner

我正在努力与Karma和Jasmine一起运行基本的UT。看起来Karma / Jasmine在运行测试时无法拾取模块。运行npm start时,不会出现相同的错误。

我收到以下错误:

Chrome 69.0.3497 (Windows 10 0.0.0) ERROR
      {
        "message": "An error was thrown in afterAll\nUncaught Error: [$injector:nomod] Module 'UTAppV2' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.\nhttps://errors.angularjs.org/1.7.4/$injector/nomod?p0=UTAppV2",
        "str": "An error was thrown in afterAll\nUncaught Error: [$injector:nomod] Module 'UTAppV2' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.\nhttps://errors.angularjs.org/1.7.4/$injector/nomod?p0=UTAppV2"
      }
Chrome 69.0.3497 (Windows 10 0.0.0): Executed 1 of 1 ERROR (0.01 secs / 0.001 secs)
npm ERR! Test failed.  See above for more details.

我的Karma.conf.js文件

module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine'],
    files: [
      'node_modules/angular/angular.js',
      'node_modules/angular-mocks/angular-mocks.js',
      'app/*.spec.js',
      'app/*.component.js',
      'app/*.module.js',
      'app.js'
    ],
    exclude: [],
    preprocessors: {},
    reporters: ['progress'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: true,
    concurrency: Infinity,
  })
}

Package.json文件

{
  "name": "uttestingv2",
  "version": "1.0.0",
  "description": "UT Testing V2",
  "main": "index.js",
  "scripts": {
    "test": "karma start karma.conf.js",
    "start": "http-server -a localhost -p 8000 -c-1"
  },
  "author": "Luke",
  "license": "ISC",
  "dependencies": {
    "angular": "^1.7.4",
    "angular-mocks": "^1.7.4",
    "jasmine": "^3.2.0",
    "karma": "^3.0.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-jasmine": "^1.1.2"
  }
}

Test.spec.js文件

describe('Basic Test', function () {
    beforeEach(module('UTAppV2'));
    it('has a dummy spec to test', function () {
        expect(4).toBe(4);
    });
});

App.js

angular.module('UTAppV2', []);

Index.html

<!doctype html>
<html ng-app="UTAppV2">

   <head>
      <script src = "node_modules/angular/angular.js"></script>
      <script src="app.js"></script>
   </head>

   <body>
      <div>
        <p>Nothing here {{'yet' + '!'}}</p>
      </div>
   </body>
</html>

运行测试时,如何解决以下错误:

  

模块'UTAppV2'不可用!

0 个答案:

没有答案