我正在尝试为我的Angular 4.1.3应用程序设置测试。我试图遵循这个:https://angular.io/docs/ts/latest/guide/testing.html#!#1st-karma-test
我遇到的问题是,如果我尝试引入任何依赖项,我就会开始:
未捕获的SyntaxError:意外的令牌导入
这是我的karma.conf.ts:
// karma.conf.ts
module.exports = function (config) {
config.set({
basePath: '/app',
frameworks: ['jasmine'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
files: [
{ pattern: '/components/**/*.spec.ts', watched: true },
{ pattern: '/tests/*.spec.ts', watched: true }
],
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
});
};

这是我的测试:
import { TestBed } from '@angular/core/testing';
import { DatePipe } from '../helpers/pipes/date.pipe';
describe('DatePipe: Pipe', () => {
let pipe: DatePipe;
beforeEach(() => {
pipe = new DatePipe();
});
afterEach(() => {
pipe = null;
});
//create the test data
let d: Date = new Date(2017, 1, 1);
let format: string = 'MM/DD/YYYY';
it('convert the date into a formatted string', () => {
expect(pipe.transform(d, format)).toBe('01/01/2017');
});
});

我可能错过了一些配置设置,但我无法弄清楚是什么。
非常感谢任何帮助。
谢谢。