From 48697a2b86dbb12ea8de64cc5fece7caf68b321e Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Mon, 17 Oct 2011 16:56:56 -0700
Subject: 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
---
test/CompilerSpec.js | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
(limited to 'test/CompilerSpec.js')
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("
" + html + "
");
- 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('');
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() {
'x' +
'after' +
'');
- });
+ }));
it('should process markup before directives', function() {
--
cgit v1.2.3