找到了一种方法
:before
选择器使用
window
对象和
getComputedStyle
:
it('should say "Checked" when checkbox is checked and "NOT Checked" when not checked', () => {
const check = el.query(By.css('#myCheck')).nativeElement;
let content = window.getComputedStyle('.label')).nativeElement, ':before').getPropertyValue('content');
expect(content).toBe('NOT Checked');
check.click();
fixture.detectChanges();
content = window.getComputedStyle('.label')).nativeElement, ':before').getPropertyValue('content');
expect(content).toBe('Checked');
});