Skip to content

Commit c141c5f

Browse files
committed
test(card-img): coverage
1 parent 8f52541 commit c141c5f

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
import { Component, DebugElement } from '@angular/core';
2+
import { ComponentFixture, TestBed } from '@angular/core/testing';
13
import { CardImgDirective } from './card-img.directive';
2-
import { TestBed } from '@angular/core/testing';
4+
import { By } from '@angular/platform-browser';
5+
6+
@Component({
7+
imports: [CardImgDirective],
8+
template: ` <div [cCardImg]="orientation"></div> `
9+
})
10+
export class TestComponent {
11+
orientation: 'top' | 'bottom' | 'start' | 'end' | undefined = undefined;
12+
}
313

414
describe('CardImgDirective', () => {
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+
fixture = TestBed.createComponent(TestComponent);
24+
component = fixture.componentInstance;
25+
debugElement = fixture.debugElement.query(By.directive(CardImgDirective));
26+
fixture.detectChanges(); // initial binding
27+
});
28+
529
it('should create an instance', () => {
630
TestBed.runInInjectionContext(() => {
731
const directive = new CardImgDirective();
832
expect(directive).toBeTruthy();
933
});
1034
});
35+
36+
it('should have css classes', () => {
37+
component.orientation = 'start';
38+
fixture.detectChanges();
39+
expect(debugElement.nativeElement).toHaveClass('rounded-start');
40+
component.orientation = 'end';
41+
fixture.detectChanges();
42+
expect(debugElement.nativeElement).toHaveClass('rounded-end');
43+
component.orientation = 'top';
44+
fixture.detectChanges();
45+
expect(debugElement.nativeElement).toHaveClass('card-img-top');
46+
component.orientation = 'bottom';
47+
fixture.detectChanges();
48+
expect(debugElement.nativeElement).toHaveClass('card-img-bottom');
49+
});
1150
});

projects/coreui-angular/src/lib/card/card.component.spec.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ describe('CardComponent', () => {
99
beforeEach(waitForAsync(() => {
1010
TestBed.configureTestingModule({
1111
imports: [CardComponent]
12-
})
13-
.compileComponents();
12+
}).compileComponents();
1413
}));
1514

1615
beforeEach(() => {

0 commit comments

Comments
 (0)