【发布时间】:2018-08-27 20:46:05
【问题描述】:
我正在使用 TestBed 进行 Angular 2+ 单元测试。 场景,我想验证我的组件,那个伪元素的颜色。
组件.ts
label::before {
right: 0;
background-color: red;
}
@Component({
selector: 'app-test',
template: `
<div><label>a label</label></div>
`,
styleUrls: ['./test.component.scss'],
})
export class TestComponent {
}
所以我在写单元测试的时候,想验证伪元素背景颜色
beforeEach(() => {
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should set background color', () => {
const ele = fixture.debugElement.query(By.css('label::before')).nativeElement; // error here
// not sure how to use by.css to locate on the pseudo element
expect(ele.backgroundColor).toBe('....');
});
【问题讨论】:
标签: css angular unit-testing pseudo-element