forked from PatrickJS/PatrickJS-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.component.spec.ts
53 lines (46 loc) · 1.41 KB
/
home.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
52
53
import {
inject,
TestBed
} from '@angular/core/testing';
import { Component } from '@angular/core';
import {
BaseRequestOptions,
ConnectionBackend,
Http
} from '@angular/http';
import { MockBackend } from '@angular/http/testing';
// Load the implementations that should be tested
import { AppState } from '../app.service';
import { HomeComponent } from './home.component';
import { Title } from './title';
describe('Home', () => {
// provide our implementations or mocks to the dependency injector
beforeEach(() => TestBed.configureTestingModule({
providers: [
BaseRequestOptions,
MockBackend,
{
provide: Http,
useFactory: function(backend: ConnectionBackend, defaultOptions: BaseRequestOptions) {
return new Http(backend, defaultOptions);
},
deps: [MockBackend, BaseRequestOptions]
},
AppState,
Title,
HomeComponent
]
}));
it('should have default data', inject([ HomeComponent ], (home: HomeComponent) => {
expect(home.localState).toEqual({ value: '' });
}));
it('should have a title', inject([ HomeComponent ], (home: HomeComponent) => {
expect(!!home.title).toEqual(true);
}));
it('should log ngOnInit', inject([ HomeComponent ], (home: HomeComponent) => {
spyOn(console, 'log');
expect(console.log).not.toHaveBeenCalled();
home.ngOnInit();
expect(console.log).toHaveBeenCalled();
}));
});