-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.component.spec.ts
38 lines (33 loc) · 1.06 KB
/
display.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DisplayComponent } from './display.component';
import { Component } from '@angular/core';
@Component({
template: `<app-display [counter]="counter"></app-display>`,
})
class TestHostComponent {
counter: number;
}
describe('CounterComponent', () => {
let testHost: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
let resultEl: Element;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DisplayComponent, TestHostComponent],
});
fixture = TestBed.createComponent(TestHostComponent);
testHost = fixture.componentInstance;
resultEl = fixture.nativeElement.querySelector('.result');
fixture.detectChanges();
}));
it('should display counter value if counter > 0', () => {
testHost.counter = 6;
fixture.detectChanges();
expect(resultEl.textContent).toBe('6');
});
it('should not display counter value if counter === 0', () => {
testHost.counter = 0;
fixture.detectChanges();
expect(resultEl.textContent).toBe('');
});
});