Skip to content

Commit 4cd332c

Browse files
committed
test(rounded): css classes coverage
1 parent 4db2d18 commit 4cd332c

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 { RoundedDirective } from './rounded.directive';
3+
import { Component, DebugElement, input } from '@angular/core';
4+
import { By } from '@angular/platform-browser';
5+
6+
@Component({
7+
imports: [RoundedDirective],
8+
template: '<div [cRounded]="rounded()"></div>'
9+
})
10+
class TestComponent {
11+
readonly rounded = input(1);
12+
}
313

414
describe('RoundedDirective', () => {
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(RoundedDirective));
27+
fixture.detectChanges();
28+
});
29+
530
it('should create an instance', () => {
631
TestBed.runInInjectionContext(() => {
7-
const directive = new RoundedDirective();
8-
expect(directive).toBeTruthy();
32+
const directive = new RoundedDirective();
33+
expect(directive).toBeTruthy();
34+
});
35+
});
36+
37+
it('should have css classes', () => {
38+
expect(debugElement.nativeElement).toHaveClass('rounded-1');
39+
fixture.componentRef.setInput('rounded', true);
40+
fixture.detectChanges();
41+
expect(debugElement.nativeElement).toHaveClass('rounded');
42+
fixture.componentRef.setInput('rounded', {
43+
top: false,
44+
end: true,
45+
circle: true,
46+
pill: true,
47+
size: 3
948
});
49+
fixture.detectChanges();
50+
expect(debugElement.nativeElement).toHaveClass('rounded-3');
51+
expect(debugElement.nativeElement).toHaveClass('rounded-end');
52+
expect(debugElement.nativeElement).toHaveClass('rounded-circle');
53+
expect(debugElement.nativeElement).toHaveClass('rounded-pill');
54+
expect(debugElement.nativeElement.classList.length).toBe(4);
55+
fixture.componentRef.setInput('rounded', {});
56+
fixture.detectChanges();
57+
expect(debugElement.nativeElement.classList.length).toBe(0);
58+
fixture.componentRef.setInput('rounded', 1234n);
59+
fixture.detectChanges();
60+
expect(debugElement.nativeElement.classList.length).toBe(0);
1061
});
1162
});

0 commit comments

Comments
 (0)