【问题标题】:Angular Karma Throws Uncaught Error: Missing jasmine.jsAngular Karma 引发未捕获的错误:缺少 jasmine.js
【发布时间】:2019-04-08 11:59:23
【问题描述】:

我创建了一个新的 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,但没有帮助

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

【问题讨论】:

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


    【解决方案1】:

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

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

    现在一切正常!

    【讨论】:

    • 同样的问题,感谢您发布解决方案。
    猜你喜欢
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 2018-09-27
    • 1970-01-01
    • 2013-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多