【发布时间】:2019-03-24 01:43:46
【问题描述】:
我正在做两个测试。
检查 h1 标签是否包含文本,即不为空。
检查h1标签是否包含title-icon /title-icon。
COMPONENT.SPEC.TS
<h1 class="head"><title-icon></title-icon>Confirmation</h1>
COMPONENT.HTML
import {async,ComponentFixture,TestBed} from '@angular/core/testing';
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
import {ConfirmationDemoComponent} from './confirmation-demo.component';
describe('ConfirmationDemoComponent', () => {
let component: ConfirmationDemoComponent;
let fixture: ComponentFixture < ConfirmationDemoComponent > ;
let compiled;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ConfirmationDemoComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ConfirmationDemoComponent);
component = fixture.componentInstance;
fixture.detectChanges();
compiled = fixture.debugElement.nativeElement;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('-> should render text inside an h1 tag', async(() => {
expect(compiled.querySelector('h1').textContent).not.toEqual(0);
}));
it('-> should render a <title-icon><title-icon> within an h1 tag', async(() => {
}));
});
【问题讨论】:
标签: angular typescript unit-testing jasmine