Angular Karma Throws Uncaught Error: Missing jasmine.js

Angular Karma Throws Uncaught Error: Missing jasmine.js

我创建了一个新的 angular 项目并想 运行 使用 ng test 进行测试。但是我遇到了很多 Pattern ** does not match any file 错误。

已启动 chrome window 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
  });
};

我想到并尝试做的事情:

我对整个测试主题还很陌生,我不知道如何解决这个错误。我需要更改什么?

好的,在进一步搜索问题后,我发现我的项目路径对因果报应无效: F:\Projects19.04.05 - 2019.04.08[Angular] My Project\my-project

导致问题的字符是方括号 [ ]

现在一切正常!