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

Commit9f68509

Browse files
committed
test(icons-angular): update
1 parent82180e5 commit9f68509

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

‎projects/coreui-icons-angular/src/lib/icon/icon.component.spec.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,29 @@ import { IconSetService } from '../icon-set';
88
import{By}from'@angular/platform-browser';
99

1010
@Component({
11-
template:`
12-
<div>
13-
<c-icon #icon name="cil-list" size="lg"></c-icon>
14-
</div>`
11+
template:'<c-icon #icon name="cil-list" size="lg" />',
12+
standalone:true,
13+
imports:[IconComponent],
14+
providers:[IconSetService]
1515
})
1616
classTestComponent{
17-
@ViewChild('icon',{read:IconComponent})iconRef!:IconComponent;
17+
@ViewChild('icon',{read:IconComponent})iconRef!:IconComponent;
1818

1919
constructor(
2020
publiciconSet:IconSetService
2121
){
22-
this.iconSet.icons={cilList};
22+
this.iconSet.icons={cilList};
2323
}
2424
}
2525

26-
2726
describe('IconComponent',()=>{
2827
letinputEl:DebugElement;
2928
letcomponent:TestComponent;
3029
letfixture:ComponentFixture<TestComponent>;
3130

3231
beforeEach(async()=>{
3332
TestBed.configureTestingModule({
34-
declarations:[TestComponent],
35-
imports:[IconComponent,HtmlAttributesDirective],
33+
imports:[TestComponent,IconComponent,HtmlAttributesDirective],
3634
providers:[IconSetService]
3735
}).compileComponents();
3836

‎projects/coreui-icons-angular/src/lib/icon/icon.directive.spec.ts‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{Component,DebugElement,Renderer2,Type,ViewChild}from'@angular/core';
1+
import{Component,DebugElement,ElementRef,Renderer2,Type,ViewChild}from'@angular/core';
22
import{ComponentFixture,TestBed}from'@angular/core/testing';
33
import{By,DomSanitizer}from'@angular/platform-browser';
44

@@ -7,8 +7,10 @@ import { IconSetService } from '../icon-set';
77
import{cilList}from'@coreui/icons';
88

99
@Component({
10-
template:`
11-
<svg [cIcon]="this.iconSet.icons.cilList" size="lg" class="test" title="Test"></svg>`
10+
template:'<svg [cIcon]="this.iconSet.icons.cilList" size="lg" class="test" title="Test"></svg>',
11+
standalone:true,
12+
imports:[IconDirective],
13+
providers:[IconSetService]
1214
})
1315
classTestComponent{
1416
constructor(
@@ -17,10 +19,13 @@ class TestComponent {
1719
this.iconSet.icons={ cilList};
1820
}
1921

20-
@ViewChild(IconDirective,{read:IconDirective})iconRef!:IconDirective;
22+
@ViewChild(IconDirective,{read:IconDirective})publiciconRef!:IconDirective;
2123
}
2224

25+
classMockElementRefextendsElementRef{}
26+
2327
describe('IconDirective',()=>{
28+
letcomponent:TestComponent;
2429
letfixture:ComponentFixture<TestComponent>;
2530
letsvgEl:DebugElement;
2631
letrenderer:Renderer2;
@@ -29,12 +34,12 @@ describe('IconDirective', () => {
2934

3035
beforeEach(()=>{
3136
TestBed.configureTestingModule({
32-
declarations:[TestComponent],
33-
providers:[IconSetService],
34-
imports:[IconDirective]
37+
providers:[IconSetService,{provide:ElementRef,useClass:MockElementRef}],
38+
imports:[IconDirective,TestComponent]
3539
}).compileComponents();
3640

3741
fixture=TestBed.createComponent(TestComponent);
42+
component=fixture.componentInstance;
3843
fixture.detectChanges();
3944
svgEl=fixture.debugElement.query(By.css('svg'));
4045
renderer=fixture.componentRef.injector.get(Renderer2asType<Renderer2>);
@@ -43,16 +48,27 @@ describe('IconDirective', () => {
4348
});
4449
it('should create an instance',()=>{
4550
TestBed.runInInjectionContext(()=>{
46-
constdirective=newIconDirective(renderer,svgEl,sanitizer,iconSetService);
51+
constdirective=newIconDirective();
4752
expect(directive).toBeTruthy();
4853
});
4954
});
55+
56+
it('service should exist',()=>{
57+
expect(component.iconSet).toBeTruthy();
58+
});
59+
60+
it('icon component should render',()=>{
61+
expect(component.iconRef).toBeTruthy();
62+
expect(component.iconRef.code()).toBe(component.iconSet.icons['cilList']);
63+
});
64+
5065
it('icon classes should be applied',()=>{
5166
expect(svgEl.nativeElement).toBeTruthy();
5267
expect(svgEl.nativeElement).toHaveClass('icon');
5368
expect(svgEl.nativeElement).toHaveClass('icon-lg');
5469
expect(svgEl.nativeElement).toHaveClass('test');
5570
});
71+
5672
it('icon attributes should be applied',()=>{
5773
expect(svgEl.nativeElement.getAttribute('aria-hidden')).toBe('true');
5874
expect(svgEl.nativeElement.getAttribute('pointer-events')).toBe('none');

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp