我正在使用Karma进行我的angular 7测试。运行测试后出现此错误: 项目服务 ✖应创建 HeadlessChrome 77.0.3865(Linux 0.0.0) 未捕获的[对象对象]被抛出
这是我的karma.conf.js:
// 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-phantomjs-launcher'),
require('karma-notify-reporter'),
require('karma-jasmine-html-reporter'),
require('karma-mocha-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/victi-aura'),
reports: ['html', 'lcovonly', 'text-summary', 'clover'],
fixWebpackSourcePaths: true,
thresholds: {
statements: 30,
lines: 30,
branches: 30,
functions: 30
}
},
reporters: ['mocha', 'notify'],
port: 9876,
colors: true,
logLevel: config.DEBUG,
autoWatch: true,
browsers: ['ChromeHeadless'],
singleRun: true,
restartOnFileChange: true
});
};
这是我的测试:
import { TestBed } from '@angular/core/testing';
import { CalendarDateLabelsService } from './calendar-date-labels.service';
import * as moment from 'moment';
describe('ProjectsService', () => {
let service: CalendarDateLabelsService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [CalendarDateLabelsService]
});
service = TestBed.get(CalendarDateLabelsService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
describe('updateWeeksNumber()', () => {
it('should add correctly', () => {
const firstDate = moment(service.currentDate);
service.updateWeeksNumber(1);
expect(firstDate.diff(service.currentDate, 'week')).toBe(-1);
service.updateWeeksNumber(-2);
expect(firstDate.diff(service.currentDate, 'week')).toBe(1);
});
});
});
我知道关于此错误还有另一个问题,但是我没有在提供的答案中找到解决方案。我已经尝试删除node_module目录并再次安装它,但是没有用。