-
Notifications
You must be signed in to change notification settings - Fork 112
/
Copy pathcounter.component.spec.ts
51 lines (42 loc) · 1.15 KB
/
counter.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
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
ComponentFixture,
TestBed,
async,
discardPeriodicTasks,
fakeAsync,
tick
} from '@angular/core/testing';
import { CounterComponent } from './counter.component';
describe('CounterComponent', () => {
let component: CounterComponent;
let fixture: ComponentFixture<CounterComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CounterComponent]
});
}));
beforeEach(() => {
fixture = TestBed.createComponent(CounterComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
afterEach(() => {
// destroy the component to cancel the timer again
fixture.destroy();
});
it(
'CounterComponent should count',
fakeAsync(() => {
// you need to call the ngOnInit explicitly, and inside the
// fakeAsync() for the tick() to work
component.ngOnInit();
expect(component.currentCounter).toBe(0);
tick(500);
expect(component.currentCounter).toBe(0);
// after 1000ms the counter should have increased
tick(500);
expect(component.currentCounter).toBe(1);
discardPeriodicTasks();
})
);
});