Angular Karma引发未捕获的错误:缺少jasmine.js

时间:2019-04-08 11:59:24

标签: angular angular-cli karma-jasmine karma-runner angular-testing

我创建了一个新的angular项目,并希望通过ng test运行测试。但是我遇到很多Pattern ** does not match any file错误。

启动的Chrome窗口remains blank出现了一个未捕获的Chrome错误:Missing jasmine.js

简化的控制台输出:

my-project>ng test
WARN [watcher]: Pattern "my-project\node_modules\jasmine-core\lib/jasmine-core/jasmine.js" does not match any file.
WARN [watcher]: Pattern "my-project\node_modules\karma-jasmine\lib\boot.js" does not match any file.
WARN [watcher]: Pattern "my-project\node_modules\karma-jasmine\lib\adapter.js" does not match any file.
WARN [watcher]: Pattern "my-project\node_modules\karma-jasmine-html-reporter\src/css/jasmine.css" does not match any file.
WARN [watcher]: Pattern "my-project\node_modules\karma-jasmine-html-reporter\src/lib/html.jasmine.reporter.js" does not match any file.
WARN [watcher]: Pattern "my-project\node_modules\karma-jasmine-html-reporter\src/lib/adapter.js" does not match any file.
WARN [karma]: No captured browser, open http://localhost:9876/
INFO [karma-server]: Karma v3.1.4 server started at http://0.0.0.0:9876/
INFO [launcher]: Launching browsers Chrome with concurrency unlimited
INFO [launcher]: Starting browser Chrome                                                                    
INFO [Chrome 73.0.3683 (Windows 10.0.0)]: Connected on socket 1nrITWT6uMuWp44pAAAA with id 90148583
Chrome 73.0.3683 (Windows 10.0.0) ERROR
  {
    "message": "Uncaught Error: Missing: jasmine.js
    at http://localhost:9876/_karma_webpack_/vendor.js:84510:9

    Error: Missing: jasmine.js
       at http://localhost:9876/_karma_webpack_/vendor.js:84510:15
       at http://localhost:9876/_karma_webpack_/vendor.js:84728:3
       at http://localhost:9876/_karma_webpack_/vendor.js:84118:10
       at Object.<anonymous>(http://localhost:9876/_karma_webpack_/vendor.js:84120:2)
       at Object../node_modules/zone.js/dist/zone-testing.js (http://localhost:9876/_karma_webpack_/vendor.js:85694:30)
        at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:79:30)
       at Module../src/test.ts (http://localhost:9876/_karma_webpack_/main.js:355:83)
       at __webpack_require__ (http://localhost:9876/_karma_webpack_/main.js:79:30)
       at checkDeferredModules (http://localhost:9876/_karma_webpack_/main.js:46:23)
       at http://localhost:9876/_karma_webpack_/main.js:152:18"
  }

我的karma.conf.js文件:

module.exports = function (config) {
  config.set({
    basePath: '.',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../coverage/my-project'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

我想出并尝试做的事情:

  • 这些模式包含反斜杠(我使用的是Windows 10),但最后使用了正常的斜杠 (例如: my-project \ node_modules \ jasmine-core \ lib / jasmine-core / jasmine.js )。这可能是问题所在。
  • Chrome错误表明jasmine.js文件丢失,因此我认为这与模式有关。
  • 我尝试更改karma.config.js文件中的basePath,但没有帮助

对于整个测试主题,我还是一个新手,我不知道如何解决此错误。我必须更改什么?

1 个答案:

答案 0 :(得分:0)

在进一步寻找问题之后,我发现我的项目之路对因果报应无效: F:\Projects\2019.04.05 - 2019.04.08[Angular] My Project\my-project

引起问题的字符是方括号[]

现在一切正常!