Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 01abe6a

Browse files
committed
test(loader): add tests for order of decorations
1 parent 6a2ebdb commit 01abe6a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/loaderSpec.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,58 @@ describe('module loader', function() {
7777
});
7878

7979

80+
it("should run decorators in order of declaration, even when mixed with provider.decorator", function() {
81+
var log = '';
82+
83+
angular.module('theModule', [])
84+
.factory('theProvider', function() {
85+
return {api: 'provider'};
86+
})
87+
.decorator('theProvider', function($delegate) {
88+
$delegate.api = $delegate.api + '-first';
89+
return $delegate;
90+
})
91+
.config(function($provide) {
92+
$provide.decorator('theProvider', function($delegate) {
93+
$delegate.api = $delegate.api + '-second';
94+
return $delegate;
95+
});
96+
})
97+
.decorator('theProvider', function($delegate) {
98+
$delegate.api = $delegate.api + '-third';
99+
return $delegate;
100+
})
101+
.run(function(theProvider) {
102+
log = theProvider.api;
103+
})
104+
105+
createInjector(['theModule']);
106+
expect(log).toBe('provider-first-second-third');
107+
});
108+
109+
110+
it("should decorate the last declared provider if multiple have been declared", function() {
111+
var log = '';
112+
113+
angular.module('theModule', []).
114+
factory('theProvider', function() { return {
115+
api: 'firstProvider'
116+
}; }).
117+
decorator('theProvider', function($delegate) {
118+
$delegate.api = $delegate.api + '-decorator';
119+
return $delegate; }).
120+
factory('theProvider', function() { return {
121+
api: 'secondProvider'
122+
}; }).
123+
run(function(theProvider) {
124+
log = theProvider.api;
125+
});
126+
127+
createInjector(['theModule']);
128+
expect(log).toBe('secondProvider-decorator')
129+
});
130+
131+
80132
it('should allow module redefinition', function() {
81133
expect(window.angular.module('a', [])).not.toBe(window.angular.module('a', []));
82134
});

0 commit comments

Comments
 (0)