Last active
August 2, 2017 12:51
-
-
Save nicobytes/1ada769aa8f4121a3d4a9dce634c52a5 to your computer and use it in GitHub Desktop.
Test for provider
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 { TestBed, inject, fakeAsync, tick } from '@angular/core/testing'; | |
| import { YourService } from './your.service'; | |
| describe('Provider: YourService', () => { | |
| //Arrange | |
| beforeEach(() => { | |
| TestBed.configureTestingModule({ | |
| providers: [ | |
| { provide: YourService, useClass: YourService }, | |
| ] | |
| }); | |
| }); | |
| it('should be created', inject([YourService], (service: YourService) => { | |
| expect(service).toBeTruthy(); | |
| })); | |
| describe("Test for doSomething", ()=>{ | |
| it('should dataResponse be defined', inject([YourService], fakeAsync((service: YourService) => { | |
| let dataResponse, dataError; | |
| service.doSomething() | |
| .then(response =>{ | |
| dataResponse = response; | |
| }) | |
| .catch(error=>{ | |
| dataError = error; | |
| }) | |
| tick(); | |
| expect(dataResponse).toBeDefined(); | |
| }))); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment