在我的Angular 6应用中,我使用业力进行单元测试,这是我的配置:
// 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
},
mime: {
'text/x-typescript': ['ts','tsx']
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'),
reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
reporters: config.angularCli && config.angularCli.codeCoverage
? ['progress', 'coverage-istanbul']
: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 60000,
flags: [
'--disable-web-security',
'--disable-gpu',
'--no-sandbox'
],
singleRun: true,
concurrency: Infinity
});
};
这是我的测试文件:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AdvancedSearchCrmdFormComponent } from './advanced-search-crmd-form.component';
import {ActivatedRoute} from '@angular/router';
import {AdvancedSearchCrmdActionsService} from '../../advanced-search-crmd-services/advanced-search-crmd-actions.service';
describe('AdvancedSearchCrmdFormComponent', () => {
let comp: AdvancedSearchCrmdFormComponent;
let fixture: ComponentFixture<AdvancedSearchCrmdFormComponent>;
// Test Suite of Component compiling
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AdvancedSearchCrmdFormComponent ],
providers: [ActivatedRoute , AdvancedSearchCrmdActionsService]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AdvancedSearchCrmdFormComponent);
comp = fixture.componentInstance;
// fixture.detectChanges();
});
// Test case of component compilation
it('AdvancedSearchCrmdFormComponent should be defined', () => {
expect(comp).toBeDefined();
});
});
并且您可以看到我有一个要运行的测试用例,但是我得到了:
/usr/local/bin/node /home/khalidvm/Desktop/WebStorm-181.5281.31/plugins/js-karma/js_reporter/karma-intellij/lib/intellijRunner.js --karmaPackageDir=/media/khalidvm/SecondDisk/SOCLE_RCD/Front/Frontend_v3_crmd/node_modules/@angular/cli --serverPort=9876 --protocol=http: --urlRoot=/ "--testName=AdvancedSearchCrmdFormComponent "
Empty test suite.
Process finished with exit code 0
建议?