aboutsummaryrefslogtreecommitdiffstats
path: root/test/CompilerSpec.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/CompilerSpec.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/CompilerSpec.js')
-rw-r--r--test/CompilerSpec.js25
1 files changed, 11 insertions, 14 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js
index 860cea4a..2dec1396 100644
--- a/test/CompilerSpec.js
+++ b/test/CompilerSpec.js
@@ -3,7 +3,7 @@
describe('compiler', function() {
var compiler, markup, attrMarkup, directives, widgets, compile, log, scope;
- beforeEach(function() {
+ beforeEach(inject(function($rootScope) {
log = "";
directives = {
hello: function(expression, element){
@@ -29,14 +29,10 @@ describe('compiler', function() {
compiler = new Compiler(markup, attrMarkup, directives, widgets);
compile = function(html){
var e = jqLite("<div>" + html + "</div>");
- return scope = compiler.compile(e)();
+ compiler.compile(e)($rootScope);
+ return scope = $rootScope;
};
- });
-
-
- afterEach(function() {
- dealoc(scope);
- });
+ }));
it('should not allow compilation of multiple roots', function() {
@@ -49,7 +45,7 @@ describe('compiler', function() {
});
- it('should recognize a directive', function() {
+ it('should recognize a directive', inject(function($rootScope) {
var e = jqLite('<div directive="expr" ignore="me"></div>');
directives.directive = function(expression, element){
log += "found";
@@ -61,10 +57,10 @@ describe('compiler', function() {
};
var template = compiler.compile(e);
expect(log).toEqual("found");
- scope = template(angular.scope());
+ scope = template($rootScope);
expect(e.hasClass('ng-directive')).toEqual(true);
expect(log).toEqual("found:init");
- });
+ }));
it('should recurse to children', function() {
@@ -94,14 +90,15 @@ describe('compiler', function() {
});
- it('should allow creation of templates', function() {
+ it('should allow creation of templates', inject(function($rootScope) {
directives.duplicate = function(expr, element){
element.replaceWith(document.createComment("marker"));
element.removeAttr("duplicate");
var linker = this.compile(element);
return function(marker) {
this.$watch('value', function() {
- var scope = linker(angular.scope(), noop);
+ var scope = $rootScope.$new;
+ linker(scope, noop);
marker.after(scope.$element);
});
};
@@ -139,7 +136,7 @@ describe('compiler', function() {
'<span>x</span>' +
'after' +
'</div>');
- });
+ }));
it('should process markup before directives', function() {