Skip to content

Commit ae3a735

Browse files
committed
test(border): css classes coverage
1 parent 45f9dc5 commit ae3a735

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,62 @@
1-
import { TestBed } from '@angular/core/testing';
1+
import { ComponentFixture, TestBed } from '@angular/core/testing';
22
import { BorderDirective } from './border.directive';
3+
import { Component, DebugElement, input } from '@angular/core';
4+
import { By } from '@angular/platform-browser';
5+
6+
@Component({
7+
imports: [BorderDirective],
8+
template: '<div [cBorder]="border()"></div>'
9+
})
10+
class TestComponent {
11+
readonly border = input(1);
12+
}
313

414
describe('BorderDirective', () => {
15+
let component: TestComponent;
16+
let fixture: ComponentFixture<TestComponent>;
17+
let debugElement: DebugElement;
18+
19+
beforeEach(() => {
20+
TestBed.configureTestingModule({
21+
imports: [TestComponent]
22+
}).compileComponents();
23+
24+
fixture = TestBed.createComponent(TestComponent);
25+
component = fixture.componentInstance;
26+
debugElement = fixture.debugElement.query(By.directive(BorderDirective));
27+
fixture.detectChanges();
28+
});
29+
530
it('should create an instance', () => {
631
TestBed.runInInjectionContext(() => {
7-
const directive = new BorderDirective();
8-
expect(directive).toBeTruthy();
32+
const directive = new BorderDirective();
33+
expect(directive).toBeTruthy();
34+
});
35+
});
36+
37+
it('should have css classes', () => {
38+
expect(debugElement.nativeElement).toHaveClass('border-1');
39+
fixture.componentRef.setInput('border', true);
40+
fixture.detectChanges();
41+
expect(debugElement.nativeElement).toHaveClass('border');
42+
fixture.componentRef.setInput('border', {
43+
top: 1,
44+
end: true,
45+
color: 'primary',
46+
start: { color: 'success', width: 2 }
947
});
48+
fixture.detectChanges();
49+
expect(debugElement.nativeElement).toHaveClass('border-top-1');
50+
expect(debugElement.nativeElement).toHaveClass('border-end');
51+
expect(debugElement.nativeElement).toHaveClass('border-color-primary');
52+
expect(debugElement.nativeElement).toHaveClass('border-start-2');
53+
expect(debugElement.nativeElement).toHaveClass('border-start-success');
54+
expect(debugElement.nativeElement.classList.length).toBe(5);
55+
fixture.componentRef.setInput('border', {});
56+
fixture.detectChanges();
57+
expect(debugElement.nativeElement.classList.length).toBe(0);
58+
fixture.componentRef.setInput('border', 1234n);
59+
fixture.detectChanges();
60+
expect(debugElement.nativeElement.classList.length).toBe(0);
1061
});
1162
});

0 commit comments

Comments
 (0)