我有一个带有打字稿2.8.0和节点版本11的angular 6项目。 我有一个功能齐全的开发应用程序,并尝试使用茉莉花业来建立单元测试环境,由于对这些框架的了解有限,所以我无法调试以下错误。
ERROR: TypeError: Cannot read property 'appendChild' of null
TypeError: Cannot read property 'appendChild' of null
at HtmlReporter.specDone (http://localhost:9876/base/node_modules/karma-jasmine-html-reporter/src/lib/html.jasmine.reporter.js?a380599bba71e79ed6dc82aa9a857815d894cfda:150:15)
at dispatch (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:4560:28)
at ReportDispatcher.specDone (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:4531:11)
at Spec.specResultCallback [as resultCallback] (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:1249:18)
at complete (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js?0b1eaf7a13cae32191eadea482cfc96ae41fc22b:567:12)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:421:1)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:188:1)
at drainMicroTaskQueue (http://localhost:9876/_karma_webpack_/webpack:/node_modules/zone.js/dist/zone.js:595:1)
我已经注释了所有规格文件中的每个规格,但是仍然导致以下错误。但是我唯一担心的是,该错误是由于karma.conf.ts
中的某些错误配置引起的以下是我的karme.config.ts文件,请向我建议对环境的更正。
// Karma配置文件,请参阅链接以获取更多信息 // 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
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: true
},
angularCli: {
environment: 'dev'
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
编辑: 以下是我的规格文件之一,并且只有一个规格被注释。因此,没有任何规范方法在运行。
从'@ angular / core / testing'导入{异步,ComponentFixture,TestBed};
从'./passback.component'导入{PassbackComponent};
describe('PassbackComponent', () => {
let component: PassbackComponent;
let fixture: ComponentFixture<PassbackComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ PassbackComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PassbackComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
// it('should create', () => {
// expect(component).toBeTruthy();
// });
});
StackOverflow中有很多类似的问题,但没有一个解决,因为其他人的规格不正确,但可能是由于其他原因而挖出的
非常感谢您。
答案 0 :(得分:0)
我遇到了同样的问题,并将其与正在运行的项目进行了比较。我通过回滚我的业力来解决它。在我的package.json中,我改变了
"karma": "^3.1.3",
到
"karma": "~3.0.0",
我相信Karma的更新已破坏了其他内容-如果我可以找到围绕它的对话,请将其发布以获取更多信息。
答案 1 :(得分:0)
karma.config.js
... reporters: ['progress', 'kjhtml'] ...