|
| 1 | +import { GithubContributor } from './githubContributor.service'; |
| 2 | + |
| 3 | +describe('service githubContributor', () => { |
| 4 | + beforeEach(angular.mock.module('<%- appName %>')); |
| 5 | + |
| 6 | + it('should be registered', inject((githubContributor: GithubContributor) => { |
| 7 | + expect(githubContributor).not.toBeNull(); |
| 8 | + })); |
| 9 | + |
| 10 | + describe('getContributors function', () => { |
| 11 | + it('should return data', inject((githubContributor: GithubContributor, $httpBackend: ng.IHttpBackendService) => { |
| 12 | + $httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(200, [{pprt: 'value'}]); |
| 13 | + let data: any[]; |
| 14 | + githubContributor.getContributors(1).then((fetchedData: any[]) => { |
| 15 | + data = fetchedData; |
| 16 | + }); |
| 17 | + $httpBackend.flush(); |
| 18 | + expect(data.length === 1).toBeTruthy(); |
| 19 | + expect(data[0]).not.toBeNull(); |
| 20 | + })); |
| 21 | + |
| 22 | + it('should define a limit per page as default value', inject((githubContributor: GithubContributor, $httpBackend: ng.IHttpBackendService) => { |
| 23 | + $httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=30').respond(200, new Array(30)); |
| 24 | + var data: any[]; |
| 25 | + githubContributor.getContributors().then((fetchedData: any[]) => { |
| 26 | + data = fetchedData; |
| 27 | + }); |
| 28 | + $httpBackend.flush(); |
| 29 | + expect(data.length === 30).toBeTruthy(); |
| 30 | + })); |
| 31 | + |
| 32 | + it('should log a error', inject((githubContributor: GithubContributor, $httpBackend: ng.IHttpBackendService, $log: ng.ILogService) => { |
| 33 | + $httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(500); |
| 34 | + githubContributor.getContributors(1); |
| 35 | + $httpBackend.flush(); |
| 36 | + expect($log.error.logs).toEqual(jasmine.stringMatching('XHR Failed for')); |
| 37 | + })); |
| 38 | + }); |
| 39 | +}); |
0 commit comments