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

Commit45c8171

Browse files
committed
refactor(text-color): host binding, cleanup, tests
1 parenta09ec7a commit45c8171

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1-
import{TestBed}from'@angular/core/testing';
1+
import{ComponentFixture,TestBed}from'@angular/core/testing';
22
import{TextColorDirective}from'./text-color.directive';
3+
import{Component,DebugElement}from'@angular/core';
4+
import{By}from'@angular/platform-browser';
5+
6+
@Component({
7+
imports:[TextColorDirective],
8+
template:'<div cTextColor="primary"></div>'
9+
})
10+
classTestComponent{}
311

412
describe('TextColorDirective',()=>{
13+
letcomponent:TestComponent;
14+
letfixture:ComponentFixture<TestComponent>;
15+
letdebugElement:DebugElement;
16+
17+
beforeEach(()=>{
18+
TestBed.configureTestingModule({
19+
imports:[TestComponent]
20+
}).compileComponents();
21+
22+
fixture=TestBed.createComponent(TestComponent);
23+
component=fixture.componentInstance;
24+
debugElement=fixture.debugElement.query(By.directive(TextColorDirective));
25+
fixture.detectChanges();
26+
});
27+
528
it('should create an instance',()=>{
629
TestBed.runInInjectionContext(()=>{
730
constdirective=newTextColorDirective();
831
expect(directive).toBeTruthy();
932
});
1033
});
34+
35+
it('should have css classes',()=>{
36+
expect(debugElement.nativeElement).toHaveClass('text-primary');
37+
});
1138
});
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import{Directive,HostBinding,input,InputSignal}from'@angular/core';
1+
import{computed,Directive,input,InputSignal}from'@angular/core';
22
import{TextColors}from'../coreui.types';
33

44
@Directive({
5-
selector:'[cTextColor]'
5+
selector:'[cTextColor]',
6+
host:{
7+
'[class]':'hostClasses()'
8+
}
69
})
710
exportclassTextColorDirective{
811
/**
@@ -11,11 +14,10 @@ export class TextColorDirective {
1114
*/
1215
readonlycolor:InputSignal<TextColors>=input('',{alias:'cTextColor'});
1316

14-
@HostBinding('class')
15-
gethostClasses():any{
17+
readonlyhostClasses=computed(()=>{
1618
constcolor=this.color();
1719
return{
1820
[`text-${color}`]:!!color
1921
};
20-
}
22+
});
2123
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp