From 9ee2cdff44e7d496774b340de816344126c457b3 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 22 Nov 2011 21:28:39 -0800 Subject: refactor(directives): connect new compiler - turn everything into a directive --- test/scenario/dslSpec.js | 82 +++++++++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 32 deletions(-) (limited to 'test/scenario') diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index 79d479bb..c757d8a4 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -1,8 +1,13 @@ 'use strict'; describe("angular.scenario.dsl", function() { + var element; var $window, $root; - var application, eventLog; + var eventLog; + + afterEach(function() { + dealoc(element); + }); beforeEach(inject(function($injector) { eventLog = []; @@ -393,28 +398,26 @@ describe("angular.scenario.dsl", function() { describe('Repeater', function() { var chain; - beforeEach(function() { - doc.append( - '' - ); + beforeEach(inject(function($compile, $rootScope) { + element = $compile( + '')($rootScope); + $rootScope.items = [{name:'misko', gender:'male'}, {name:'felisa', gender:'female'}]; + $rootScope.$apply(); + doc.append(element); chain = $root.dsl.repeater('ul li'); - }); + })); it('should get the row count', function() { chain.count(); expect($root.futureResult).toEqual(2); }); - it('should return 0 if repeater doesnt match', function() { - doc.find('ul').html(''); + it('should return 0 if repeater doesnt match', inject(function($rootScope) { + $rootScope.items = []; + $rootScope.$apply(); chain.count(); expect($root.futureResult).toEqual(0); - }); + })); it('should get a row of bindings', function() { chain.row(1); @@ -422,7 +425,7 @@ describe("angular.scenario.dsl", function() { }); it('should get a column of bindings', function() { - chain.column('gender'); + chain.column('i.gender'); expect($root.futureResult).toEqual(['male', 'female']); }); @@ -437,45 +440,60 @@ describe("angular.scenario.dsl", function() { }); describe('Binding', function() { - it('should select binding by name', function() { - doc.append('some value'); + var compile; + + beforeEach(inject(function($compile, $rootScope) { + compile = function(html, value) { + element = $compile(html)($rootScope); + doc.append(element); + $rootScope.foo = {bar: value || 'some value'}; + $rootScope.$apply(); + }; + })); + + + it('should select binding in interpolation', function() { + compile('{{ foo.bar }}'); $root.dsl.binding('foo.bar'); expect($root.futureResult).toEqual('some value'); }); - it('should select binding by regexp', function() { - doc.append('some value'); - $root.dsl.binding(/^foo\..+/); + it('should select binding in multiple interpolations', function() { + compile('{{ foo.bar }}
{{ true }}
'); + $root.dsl.binding('foo.bar'); expect($root.futureResult).toEqual('some value'); + + $root.dsl.binding('true'); + expect($root.futureResult).toEqual('true'); }); - it('should return value for input elements', function() { - doc.append(''); + it('should select binding by name', function() { + compile(''); $root.dsl.binding('foo.bar'); expect($root.futureResult).toEqual('some value'); }); - it('should return value for textarea elements', function() { - doc.append(''); - $root.dsl.binding('foo.bar'); + it('should select binding by regexp', function() { + compile('some value'); + $root.dsl.binding(/^foo\..+/); expect($root.futureResult).toEqual('some value'); }); it('should return innerHTML for all the other elements', function() { - doc.append('
some value
'); + compile('
', 'some value'); $root.dsl.binding('foo.bar'); expect($root.futureResult.toLowerCase()).toEqual('some value'); }); it('should select binding in template by name', function() { - doc.append('
foo some baz
'); - $root.dsl.binding('bar'); - expect($root.futureResult).toEqual('foo some baz'); + compile('
', 'bar');
+        $root.dsl.binding('foo.bar');
+        expect($root.futureResult).toEqual('bar');
       });
 
       it('should match bindings by substring match', function() {
-        doc.append('
binding value
'); - $root.dsl.binding('test.baz'); + compile('
', 'binding value');
+        $root.dsl.binding('foo . bar');
         expect($root.futureResult).toEqual('binding value');
       });
 
@@ -485,7 +503,7 @@ describe("angular.scenario.dsl", function() {
       });
 
       it('should return error if no binding matches', function() {
-        doc.append('some value');
+        compile('some value');
         $root.dsl.binding('foo.bar');
         expect($root.futureError).toMatch(/did not match/);
       });
-- 
cgit v1.2.3