aboutsummaryrefslogtreecommitdiffstats
path: root/test/InjectorSpec.js
diff options
context:
space:
mode:
authorMisko Hevery2011-10-17 16:56:56 -0700
committerMisko Hevery2011-11-14 16:39:31 -0800
commit48697a2b86dbb12ea8de64cc5fece7caf68b321e (patch)
tree1fa50659f0bb5de2640dea2a2e5bb5628f2bb14a /test/InjectorSpec.js
parent93b777c916ccff243c5a6080bf5f39860ac7bf39 (diff)
downloadangular.js-48697a2b86dbb12ea8de64cc5fece7caf68b321e.tar.bz2
refactor(injector): turn scope into a service
- turn scope into a $rootScope service. - injector is now a starting point for creating angular application. - added inject() method which wraps jasmine its/beforeEach/afterEach, and which allows configuration and injection of services. - refactor tests to use inject() where possible BREAK: - removed angular.scope() method
Diffstat (limited to 'test/InjectorSpec.js')
-rw-r--r--test/InjectorSpec.js29
1 files changed, 12 insertions, 17 deletions
diff --git a/test/InjectorSpec.js b/test/InjectorSpec.js
index 2c6c102a..39b20392 100644
--- a/test/InjectorSpec.js
+++ b/test/InjectorSpec.js
@@ -2,24 +2,20 @@
describe('injector', function() {
var providers;
- var cache;
var injector;
- var scope;
beforeEach(function() {
providers = extensionMap({}, 'providers');
- cache = {};
- scope = {};
- injector = createInjector(scope, providers, cache);
+ injector = createInjector(providers);
});
it("should return same instance from calling provider", function() {
- providers('text', function() { return scope.name; });
- scope.name = 'abc';
- expect(injector('text')).toEqual('abc');
- expect(cache.text).toEqual('abc');
- scope.name = 'deleted';
- expect(injector('text')).toEqual('abc');
+ var instance = {},
+ original = instance;
+ providers('instance', function() { return instance; });
+ expect(injector('instance')).toEqual(instance);
+ instance = 'deleted';
+ expect(injector('instance')).toEqual(original);
});
it("should call function", function() {
@@ -35,10 +31,9 @@ describe('injector', function() {
});
it('should inject providers', function() {
- providers('a', function() {return this.mi = 'Mi';});
- providers('b', function(mi){return this.name = mi+'sko';}, {$inject:['a']});
+ providers('a', function() {return 'Mi';});
+ providers('b', function(mi){return mi+'sko';}, {$inject:['a']});
expect(injector('b')).toEqual('Misko');
- expect(scope).toEqual({mi:'Mi', name:'Misko'});
});
@@ -76,7 +71,7 @@ describe('injector', function() {
it('should autostart eager services', function() {
var log = '';
providers('eager', function() {log += 'eager;'; return 'foo';}, {$eager: true});
- injector.eager();
+ injector = createInjector(providers);
expect(log).toEqual('eager;');
expect(injector('eager')).toBe('foo');
});
@@ -126,11 +121,11 @@ describe('injector', function() {
});
it('should infer injection on services', function() {
- var scope = angular.scope({
+ var $injector = createInjector({
a: function() { return 'a';},
b: function(a){ return a + 'b';}
});
- expect(scope.$service('b')).toEqual('ab');
+ expect($injector('b')).toEqual('ab');
});
});