【发布时间】:2019-03-24 17:56:56
【问题描述】:
我有工作 Angular 测试设置。当我测试带有嵌套组件的组件时,这会给我带来错误,这就是为什么我需要模拟这些组件。
Angular 测试文档向我们展示了其他模拟组件的方法 - 使用 NO_ERRORS_SCHEMA。当我尝试使用它时(无论是在无头模式还是使用 Chrome 的正常模式下),我的测试都会停止工作。信息看起来像这样
24 03 2019 18:48:45.750:INFO [launcher]: Starting browser Chrome
24 03 2019 18:48:49.599:WARN [karma]: No captured browser, open
http://localhost:9876/
24 03 2019 18:48:49.644:INFO [HeadlessChrome 73.0.3683 (Ubuntu
0.0.0)]: Connected on socket cQvumAWhGFfzQWh0AAAA with id 98993378
在浏览器模式下,我只能看到信息:
Karma v4.0.1 - connected
Chromium 73.0.3683 (Ubuntu 0.0.0) is idle
当我在没有 [NO_ERRORS_SCHEMA] 的情况下运行测试时,我可以看到我的测试结果,这就是为什么错误与此架构设置有关。
我的组件规格设置:
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ContactComponent } from './contact.component';
import { NO_ERRORS_SCHEMA } from '@angular/compiler/src/core';
describe('ContactComponent', () => {
let component: ContactComponent;
let fixture: ComponentFixture<ContactComponent>;
beforeEach(async () => {
TestBed.configureTestingModule({
declarations: [ContactComponent],
schemas: [NO_ERRORS_SCHEMA]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(ContactComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeFalsy();
});
});
问题是 - make 测试如何与 NO_ERRORS_SCHEMA 一起工作
我的机器 - Ubuntu 18.04,节点 11.11
"jasmine-core": "~3.3.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.0.1",
"karma-chrome-launcher": "~2.2.0",
"karma-cli": "~2.0.0",
"karma-coverage-istanbul-reporter": "^2.0.5",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
【问题讨论】:
标签: angular karma-jasmine karma-runner