githubContributor.service.spec.js
2.06 KB
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
54
55
56
57
58
59
60
61
62
(function() {
'use strict';
describe('service githubContributor', function() {
var githubContributor;
var $httpBackend;
var $log;
beforeEach(module('angular'));
beforeEach(inject(function(_githubContributor_, _$httpBackend_, _$log_) {
githubContributor = _githubContributor_;
$httpBackend = _$httpBackend_;
$log = _$log_;
}));
it('should be registered', function() {
expect(githubContributor).not.toEqual(null);
});
describe('apiHost variable', function() {
it('should exist', function() {
expect(githubContributor.apiHost).not.toEqual(null);
});
});
describe('getContributors function', function() {
it('should exist', function() {
expect(githubContributor.getContributors).not.toEqual(null);
});
it('should return data', function() {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(200, [{pprt: 'value'}]);
var data;
githubContributor.getContributors(1).then(function(fetchedData) {
data = fetchedData;
});
$httpBackend.flush();
expect(data).toEqual(jasmine.any(Array));
expect(data.length === 1).toBeTruthy();
expect(data[0]).toEqual(jasmine.any(Object));
});
it('should define a limit per page as default value', function() {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=30').respond(200, new Array(30));
var data;
githubContributor.getContributors().then(function(fetchedData) {
data = fetchedData;
});
$httpBackend.flush();
expect(data).toEqual(jasmine.any(Array));
expect(data.length === 30).toBeTruthy();
});
it('should log a error', function() {
$httpBackend.when('GET', githubContributor.apiHost + '/contributors?per_page=1').respond(500);
githubContributor.getContributors(1);
$httpBackend.flush();
expect($log.error.logs).toEqual(jasmine.stringMatching('XHR Failed for'));
});
});
});
})();