-
Notifications
You must be signed in to change notification settings - Fork 112
/
greeting.service.spec.ts
74 lines (60 loc) · 1.75 KB
/
greeting.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* tslint:disable:no-unused-variable */
import { TestBed, inject } from '@angular/core/testing';
import { GreetingService } from './greeting.service';
describe('GreetingService', () => {
describe('Manually instantiating service', () => {
let service: GreetingService;
beforeEach(() => {
service = new GreetingService();
});
afterEach(() => {
service = null;
});
it('should greet properly', () => {
expect(service.sayHi('Juri')).toBe('Hi, Juri');
});
});
describe('Configuring via TestBed', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [GreetingService]
});
});
describe('Injecting via testcase level inject', () => {
it(
'should have a service instance',
inject([GreetingService], (service: GreetingService) => {
expect(service).toBeDefined();
})
);
});
describe('Injecting via test suite level inject', () => {
let service: GreetingService;
beforeEach(
inject([GreetingService], (s: GreetingService) => {
service = s;
})
);
it('should have a service instance', () => {
expect(service).toBeDefined();
});
});
describe('Injecting via TestBed.get()', () => {
let service: GreetingService;
beforeEach(() => {
service = TestBed.get(GreetingService);
});
it('should have a service instance', () => {
expect(service).toBeDefined();
});
});
describe('Testing service functions', () => {
it(
'should greet properly',
inject([GreetingService], (service: GreetingService) => {
expect(service.sayHi('Juri')).toBe('Hi, Juri');
})
);
});
});
});