angular 6中typescript的karma和jasmine配置

angular 6中typescript的karma和jasmine配置,angular,unit-testing,typescript,jasmine,karma-jasmine,Angular,Unit Testing,Typescript,Jasmine,Karma Jasmine,我在angular 6中有一个简单的应用程序组件。我为dev和prod-build配置了我的网页包,它们都工作得很好。我正在尝试使用karma,jasmine为我的应用程序配置一个单元测试环境,但从昨天开始就没有成功。我只需要使用Coverage no e2e执行单元测试。安装我的业力和茉莉花。然后我通过karma init生成了下面的文件 //业力构形 module.exports = function(config) { config.set({ // base path th

我在angular 6中有一个简单的应用程序组件。我为dev和prod-build配置了我的网页包,它们都工作得很好。我正在尝试使用karma,jasmine为我的应用程序配置一个单元测试环境,但从昨天开始就没有成功。我只需要使用Coverage no e2e执行单元测试。安装我的业力和茉莉花。然后我通过karma init生成了下面的文件

//业力构形

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    frameworks: ['jasmine'],

    files: [
      'src/index.ts',
      'src/**/**.spec.ts'
    ],
    mime: {
      'text/x-typescript': ['ts','tsx']
    },

    // list of files / patterns to exclude
    exclude: [
    ],
    preprocessors: {
    },

    reporters: ['progress'],
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome']
    singleRun: false,
    concurrency: Infinity
  })
}
然后,我在一个名为mycomponent.spec.ts的组件中添加了一个简单的.spec.ts测试

describe('example test', function () {
    it('should be true', function () {
        expect('foo').toBe('foo');
    });
});
当我运行我的测试时,我得到下面的错误

Chrome 67.0.3396(Windows 7 0.0.0)错误{ “消息”:“未捕获语法错误后,在中引发了一个错误:意外的令牌导出”, “str”:“未捕获语法错误:意外的令牌导出”}Chrome 67.0.3396(Windows 7 0.0.0)之后引发了一个错误: 执行1个错误中的1个(0.013秒/0.001秒)


从昨天开始,我一直在尝试修复此问题并设置我的环境。我遇到了一个使用karma字体的建议。然而,当我使用它时,我得到了很多网页错误。请问我该如何设置?任何帮助都将不胜感激。

我在我的项目中添加了您的代码,并用以下代码对其进行了修改

请尝试下面的代码,如果它不工作,然后让我知道

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',

    frameworks: ['jasmine','@angular/cli' ],
        plugins: [
      require('karma-jasmine'),
      require('karma-jasmine-html-reporter'),
      require('karma-chrome-launcher'),
      require('karma-remap-istanbul'),
      require('@angular/cli/plugins/karma'),
      require('karma-coverage'),
      require('karma-sourcemap-loader'),
      require('karma-coverage-istanbul-reporter'),
      require('karma-spec-reporter')
    ],


    files: [
      'src/index.ts',
      'src/**/**.spec.ts'
    ],
    mime: {
      'text/x-typescript': ['ts','tsx']
    },
    client: {
            codeCoverage: config.angularCli.codeCoverage,
            clearContext: false
          },


    angularCli: {
            environment: 'dev',
            apps: config.angularCli.codeCoverage ? '1' : '0'
          },

    // list of files / patterns to exclude
    exclude: [
    ],
    preprocessors: {
      './src/test.ts': ['@angular/cli']
    },


    reporters: ['progress'],
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,

  })
}