我正在尝试创建一个带有测试的组件.该组件具有我想要测试的外部CSS.我想我做的一切都是正确的,但我无法通过测试.这是我的代码:app.component.spec.ts
import { AppComponent } from "./app.component";
import { async, TestBed } from "@angular/core/testing";
import { By } from "@angular/platform-browser";
describe("App Component", function () {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
}).compileComponents()
}));
it("should instantiate component", () => {
let fixture = TestBed.createComponent(AppComponent);
expect(fixture.componentInstance instanceof AppComponent).toBe(true);
});
it("should have expected <h1> text", () => {
let fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
let h1 = fixture.debugElement.query(By.css("h1"));
expect(h1.nativeElement.innerText).toBe("hello world!");
expect(h1.nativeElement.style.color).toBe("blue");
});
});
Run Code Online (Sandbox Code Playgroud)
app.component.ts:
import { Component } from "@angular/core";
@Component({
moduleId: module.id,
selector: …Run Code Online (Sandbox Code Playgroud)