首页 > 解决方案 > ng test 不执行任何测试用例

问题描述

我正在使用 angular2 并希望实现 jasmine-karma 测试。当我运行 ng test 时,它运行没有错误,但不执行任何测试用例(说 0 执行了 0 个错误)。对 test.ts 文件发出警告,"C:/Users/T01192B/Applications/capital-markets-frm-insight-profile/src/test.ts" does not match any file.它没有从路径中选择 test.ts。

尝试更改 karma.config.js 文件无效。

module.exports = function(config) {
  config.set({
    basePath: ' ',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [{
      pattern: './src/test.ts',
      watched: false
    }],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },
    mime: {
      'text/x-typescript': ['ts', 'tsx']
    },
    coverageIstanbulReporter: {
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: config.angularCli && config.angularCli.codeCoverage ?
      ['progress', 'coverage-istanbul'] :
      ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

标签: angulartesting

解决方案


推荐阅读