@Component({
})
// Created component for Test purposes
export class TestComponent{
colorName = 'blue';
}
describe('HighlightDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let component: TestComponent;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TestComponent]
}).compileComponents();
fixture = TestBed.createComponent(TestComponent);
component = fixture.componentInstance;
fixture.detectChange();
});
it('should create an instance of Test Component', () => {
expect(component).toBeTruthy();
});
it('should change background color based on directive param', () => {
const expectedColor = 'red';
component.colorName = expectedColor;
fixture.detectChanges();
const elementDirective = fixture.debugElement.query(By.css('span')).nativeElement as HTMLElement;
expect(elementDirective.style.backgroundColor).toBe(expectedColor);
});
});