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

Commita09ec7a

Browse files
committed
refactor(text-bg-color): host binding, cleanup, tests
1 parentfaab48a commita09ec7a

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
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';
2+
import{Component,DebugElement}from'@angular/core';
3+
import{By}from'@angular/platform-browser';
24
import{TextBgColorDirective}from'./text-bg-color.directive';
35

6+
@Component({
7+
imports:[TextBgColorDirective],
8+
template:'<div cTextBgColor="primary"></div>'
9+
})
10+
classTestComponent{}
11+
412
describe('TextBgColorDirective',()=>{
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(TextBgColorDirective));
25+
fixture.detectChanges();
26+
});
27+
528
it('should create an instance',()=>{
629
TestBed.runInInjectionContext(()=>{
730
constdirective=newTextBgColorDirective();
831
expect(directive).toBeTruthy();
932
});
1033
});
34+
35+
it('should have css classes',()=>{
36+
expect(debugElement.nativeElement).toHaveClass('text-bg-primary');
37+
});
1138
});
Lines changed: 8 additions & 6 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{Colors}from'../coreui.types';
33

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

14-
@HostBinding('class')
15-
gethostClasses():any{
17+
readonlyhostClasses=computed(()=>{
1618
constcolor=this.textBgColor();
1719
return{
1820
[`text-bg-${color}`]:!!color
19-
};
20-
}
21+
}asRecord<string,boolean>;
22+
});
2123
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp