【发布时间】:2022-10-18 20:29:03
【问题描述】:
我想测试几种环境的不同背景颜色。 您可以在环境 bmw、audi 和 vw 之间切换。根据所选环境,背景颜色会发生变化。现在我想为此编写一个 Angular 测试。如何更改动态 css 类并对其进行测试。请在下面输入我的代码。
谢谢你。
component.html 的内容
<span class="car-models {{ car }}">Welcome</span>
component.scss 的内容
.car-models {
&.bmw{
background: blue;
}
&.audi {
background: yellow;
}
&.vw {
background: black;
}
}
component.spec.ts 的内容
beforeEach(() => {
fixture = TestBed.createComponent(MyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('check background color', () => {
//if <span class="car-models bmw">Welcome</span>
// than should the backgroundcolor of the text blue;
// if <span class="car-models audi">Welcome</span>
// than should the background color of the text yellow
});
【问题讨论】:
标签: css angular typescript unit-testing angular-test