-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.js
132 lines (110 loc) · 3.47 KB
/
code.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
angular.module('myFirst', []).controller('MyFirstCntl', function ($scope, userService) {
$scope.fullName = userService.getFullName();
}).factory('userService', function () {
var user = {
name: 'John',
surname: 'Nowak'
};
return {
getFullName: function () {
return user.name + ' ' + user.surname;
}
}
});
angular.module('myFirst', []).controller('MyFirstCntl', function ($scope, userService) {
$scope.fullName = userService();
}).factory('userService', function () {
var user = {
name: 'John',
surname: 'Nowak'
};
return function () {
return user.name + ' ' + user.surname;
}
});
angular.module('myFirst', []).controller('MyFirstCntl', function ($scope, userService) {
$scope.fullName = userService;
}).factory('userService', function () {
var user = {
name: 'John',
surname: 'Nowak'
};
return user.name + ' ' + user.surname;
});
function UnicornLauncher(apiToken) {
this.launchedCount = 0;
this.launch = function () {
//uses apiToken somehow
this.launchedCount++;
}
}
angular.module('myFirst', []).config(function (unicornLauncherProvider) {
unicornLauncherProvider.setGalaxName('Andromeda');
}).provider('unicornLauncher', function () {
var galaxyName = 'the Milky Way';
this.setGalaxyName = function (galaxy) {
galaxyName = galaxy;
};
this.$get = ["apiToken", function (apiToken) {
return new UnicornLauncher(apiToken, galaxyName);
}];
}).controller('DemoCntl', function ($scope, unicornLauncher) {
unicornLauncher.launch();
});
angular.module('myFirst', []).config(function ($routeProvider) {
$routeProvider.when('/books', {
templateUrl: '/library/html/books.html',
controller: 'BooksCntl'
}).when('/articles', {
templateUrl: '/library/html/articles.html',
controller: 'ArticlesCntl'
})
});
describe('A suite', function () {
it('contains spec with an expectation', function () {
expect(true).toBe(true);
});
});
describe('Calculator Controller', function () {
beforeEach(module('app'));
beforeEach(inject(function ($controller, $rootScope) {
var $scope = $rootScope.$new();
$controller('CalculatorCtrl', {$scope: $scope});
}));
describe('factorial tests', function () {
it('return 1 for 0!', function () {
// given when then
expect($scope.factorial(0)).toBe(1);
});
});
});
describe('data service tests', function () {
var someDataService;
beforeEach(module('app'));
beforeEach(inject(function (_someDataService_) {
someDataService = _someDataService_;
}));
describe('get data method', function () {
it('should return data', function () {
// given
var data = [];
// when
data = someDataService.getData();
expect(data.length).toEqual(10);
});
});
});
describe('testing directive', function() {
'use strict';
var $compile, $rootScope;
beforeEach(module('moduleName'));
beforeEach(inject(function(_$compile_, _$rootScope_){
$compile = _$compile_;
$rootScope = _$rootScope_;
}));
it('should replace the directive with an appropriate content', function() {
var element = $compile('<directive-name></directive-name>')($rootScope);
$rootScope.$digest();
expect(element.html()).toContain('expected content');
});
});