我尝试测试 Angular 材料垫扩展面板打开。
所以,我用下面的代码测试。
describe('Selected first expansion panel', () => {
beforeEach(() => {
const header = fixture.debugElement.query(By.css('#panel1 .mat-expansion-panel-header'))!.nativeElement;
header.click();
fixture.detectChanges();
});
it('should show first expansion panel content', () => {
const first = fixture.debugElement.query(By.css('#panel1 .mat-expansion-panel-content'))!.nativeElement;
console.log(first.style);
expect(first.style.visibility).toEqual('visible');
});
});
控制台(console.log(first.style))下面的输出在“它”中
CSSStyleDeclaration {alignContent: "", alignItems: "", alignSelf: "", alignmentBaseline: "", all: "", …}
cssText: "visibility: visible;"
length: 1
parentRule: null
cssFloat: ""
0: "visibility"
...
visibility: "visible"
...
但是,失败的 expect(first.style.visibility).toEqual('visible') 与Expected '' 等于 'visible'。
怎么获得