-
Notifications
You must be signed in to change notification settings - Fork 0
/
ng.inject.spec.js
69 lines (60 loc) · 3.41 KB
/
ng.inject.spec.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
describe('ng-injectJS', function() {
var _provide = null;
beforeEach(module('ngInjectJS'));
beforeEach(module(function($provide) {
_provide = $provide;
}));
describe('lifetimes', function() {
describe('singleton', function() {
it('should defer to angularjs injector when no lifetime argument is passed', inject(function($injector) {
_provide.service('test_service', function() {});
expect($injector.has('test_service')).toBeTruthy();
}));
return it('should defer to angularjs injector when singleton lifetime is passed', inject(function($injector) {
_provide.service('test_service', function() {}, 'singleton');
expect($injector.has('test_service')).toBeTruthy();
}));
});
describe('transient', function() {
it('should create one instance per dependency request', inject(function($injector) {
var transient1, transient2;
_provide.service('transient_service', function() {}, 'transient');
transient1 = $injector.get('transient_service');
transient2 = $injector.get('transient_service');
expect(transient1).not.toBe(transient2);
}));
});
describe('state', function() {
init = function () {
_provide.service('state_service', function(transient_service) { this.transient_service = transient_service; }, 'state');
_provide.service('transient_service', function() {}, 'transient');
};
it('should create one instance for the entire application until state is cleared', inject(function($injector, $injectJS) {
init();
var state1, state2;
state1 = $injector.get('state_service');
state2 = $injector.get('state_service');
var transient1 = state1.transient_service;
expect(state2.transient_service).toBe(transient1);
$injectJS.clearState();
state1 = $injector.get('state_service');
state2 = $injector.get('state_service');
expect(state1.transient_service).toBe(state2.transient_service);
expect(state1.transient_service).not.toBe(transient1);
}));
it('should always point all dependants to the latest instance of the object', inject(function($injector, $injectJS) {
init();
_provide.service('transient_service_2', function (state_service) {this.state_service = state_service}, 'transient');
var transient1 = $injector.get('transient_service_2');
var transient2 = $injector.get('transient_service_2');
expect(transient1).not.toBe(transient2);
expect(transient1.state_service).toBe(transient2.state_service);
expect(transient1.state_service.transient_service).toBe(transient2.state_service.transient_service);
$injectJS.clearState();
var transient3 = $injector.get('transient_service_2');
expect(transient1.state_service).toBe(transient3.state_service);
expect(transient1.state_service.transient_service).toBe(transient3.state_service.transient_service);
}));
});
});
});