【问题标题】:Karma shows "Incomplete: no spec found" in angular project although spec files exist尽管存在规范文件,业力在 Angular 项目中显示“不完整:未找到规范”
【发布时间】:2023-03-03 21:08:01
【问题描述】:

我在规范文件中为几个组件编写了测试用例,但是当我运行ng-test 时,它仍然显示"Incomplete: no specs found, , randomized with seed ######"。我的业力文件看起来像这样

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

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/tenms'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true
  });
};

src 文件夹中的条目test.ts 文件看起来像这样

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
    BrowserDynamicTestingModule,
    platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

项目中有几个针对不同组件的规范文件。其中一些包含一些错误。是否因为规范文件中的某些文件是使用相对路径导入的错误而无法找到规范文件?我应该怎么做才能解决这个问题?提前谢谢

【问题讨论】:

    标签: angular automated-tests karma-jasmine


    【解决方案1】:

    可能有任何编译器错误导致 Karma Runner 停止,或者您可以按如下方式查找您的 test.ts 文件-

    // 然后我们找到所有的测试。 const context = require.context('./', true, /.spec.ts$/);

    确保在此处允许所有规范。

    【讨论】:

      【解决方案2】:

      得到了答案。我必须更正 spec.ts 文件中的所有错误以避免编译时错误。之后一切正常。

      【讨论】:

        猜你喜欢
        • 2020-03-31
        • 2021-05-20
        • 1970-01-01
        • 2018-06-10
        • 1970-01-01
        • 2017-03-19
        • 1970-01-01
        • 2020-04-13
        • 1970-01-01
        相关资源
        最近更新 更多