Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4cd332c

Browse files
committed
test(rounded): css classes coverage
1 parent4db2d18 commit4cd332c

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed
Lines changed: 54 additions & 3 deletions
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+
classTestComponent{
11+
readonlyrounded=input(1);
12+
}
313

414
describe('RoundedDirective',()=>{
15+
letcomponent:TestComponent;
16+
letfixture:ComponentFixture<TestComponent>;
17+
letdebugElement: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-
constdirective=newRoundedDirective();
8-
expect(directive).toBeTruthy();
32+
constdirective=newRoundedDirective();
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)

[8]ページ先頭

©2009-2025 Movatter.jp