-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathname.componnent.spec.ts
45 lines (34 loc) · 1.27 KB
/
name.componnent.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
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { of } from 'rxjs';
import { NameService } from './name.service';
import { NameComponent } from './name.component';
describe('NameComponent', () => {
let nameServiceSpy: jasmine.SpyObj<NameService>;
let component: NameComponent;
let fixture: ComponentFixture<NameComponent>;
beforeEach(() => {
nameServiceSpy = jasmine.createSpyObj('NameService', ['loadName', 'name$']);
TestBed.configureTestingModule({
declarations: [ NameComponent ],
providers: [ { provide: NameService, useValue: nameServiceSpy } ]
});
fixture = TestBed.createComponent(NameComponent);
component = fixture.componentInstance;
});
it('should create', () => {
// Checking component creation
expect(component).toBeTruthy();
});
it('should call loadName on NameService', () => {
fixture.detectChanges();
// Checking loadName call
expect(nameServiceSpy.loadName).toHaveBeenCalledWith();
});
it('should display NameService name', () => {
// Setting name in service
nameServiceSpy.name$.and.returnValue(of('the name'));
fixture.detectChanges();
// Checking displayed name
expect(fixture.debugElement.nativeElement.innerText).toEqual('the name');
});
});