-
Notifications
You must be signed in to change notification settings - Fork 112
/
async.service.spec.ts
44 lines (35 loc) · 967 Bytes
/
async.service.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
/* tslint:disable:no-unused-variable */
import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
import { AsyncService } from './async.service';
describe('AsyncService', () => {
let service: AsyncService;
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AsyncService]
});
// inject the service
service = TestBed.get(AsyncService);
});
it('should have a service instance', () => {
expect(service).toBeDefined();
});
it('should handle a simple async scenario', async(() => {
service.simpleAsync().then(result => {
expect(result).toBe('Hi there');
});
}));
it(
'should work with fakeAsync',
fakeAsync(() => {
let value;
service.simpleAsync().then(result => {
value = result;
});
expect(value).not.toBeDefined();
tick(50);
expect(value).not.toBeDefined();
tick(50);
expect(value).toBeDefined();
})
);
});