Skip to content

Commit 158c1fc

Browse files
ofirdaganShahar Talmi
authored and
Shahar Talmi
committed
fix(service to share): call $digest in the decorator
Closes #26
1 parent 35799da commit 158c1fc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

app/scripts/services/widgets.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
'use strict';
2-
32
angular.module('angularWidgetInternal')
43
.provider('widgets', function () {
54
var manifestGenerators = [];
@@ -28,7 +27,7 @@ angular.module('angularWidgetInternal')
2827
var original = service[method];
2928
service[method] = function () {
3029
if (arguments.length >= count && !$rootScope.$$phase) {
31-
$rootScope.$evalAsync();
30+
$rootScope.$applyAsync();
3231
}
3332
return original.apply(service, arguments);
3433
};

test/spec/services/widgets.spec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ describe('Unit testing widgets service', function () {
123123
module(function (widgetsProvider) {
124124
widgetsProvider.addServiceToShare('shahata', {method: 3});
125125
}, {shahata: {method: spy}});
126-
inject(function (widgets, shahata, $rootScope) {
126+
inject(function (widgets, shahata, $rootScope, $timeout) {
127+
spyOn($rootScope, '$digest');
127128
shahata.method(1, 2, 3);
129+
$timeout.flush();
128130
expect(spy).toHaveBeenCalledWith(1, 2, 3);
129-
expect($rootScope.$$asyncQueue.length).toBe(1);
131+
expect($rootScope.$digest).toHaveBeenCalled();
130132
});
131133
});
132134

@@ -149,9 +151,11 @@ describe('Unit testing widgets service', function () {
149151
module(function (widgetsProvider) {
150152
widgetsProvider.addServiceToShare('shahata', ['method']);
151153
}, {shahata: {method: spy}});
152-
inject(function (widgets, shahata, $rootScope) {
154+
inject(function (widgets, shahata, $rootScope, $timeout) {
155+
spyOn($rootScope, '$digest');
153156
shahata.method();
154-
expect($rootScope.$$asyncQueue.length).toBe(1);
157+
$timeout.flush();
158+
expect($rootScope.$digest).toHaveBeenCalled();
155159
});
156160
});
157161

0 commit comments

Comments
 (0)