Last active
January 22, 2018 04:31
-
-
Save PavanKu/25a28733a2c804bb3c6f8a2c5e547672 to your computer and use it in GitHub Desktop.
Unit Testing of Component which Uses Service And Contain Child Component in AngularJS V5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | |
import { AddressBookComponent } from './address-book.component'; | |
import { NO_ERRORS_SCHEMA } from '@angular/core'; | |
import { AddressBookDataService } from '../services/address-book-data.service'; | |
describe('AddressBookComponent', () => { | |
let component: AddressBookComponent; | |
let fixture: ComponentFixture<AddressBookComponent>; | |
let addressBookDataServiceStub: any; | |
let addressBookDataService: any; | |
beforeEach(async(() => { | |
addressBookDataServiceStub = { | |
getContacts: () => [] | |
}; | |
TestBed.configureTestingModule({ | |
declarations: [ AddressBookComponent ], | |
schemas: [NO_ERRORS_SCHEMA], | |
providers: [{ | |
provide: AddressBookDataService, | |
useValue: addressBookDataServiceStub | |
}] | |
}) | |
.compileComponents(); | |
})); | |
beforeEach(() => { | |
fixture = TestBed.createComponent(AddressBookComponent); | |
component = fixture.componentInstance; | |
addressBookDataService = TestBed.get(AddressBookDataService); | |
fixture.detectChanges(); | |
}); | |
it('should create', () => { | |
expect(component).toBeTruthy(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment