From ef4bb28be13e99f96c9ace5936cf26a174a0e5f0 Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Sat, 12 Feb 2011 10:13:28 -0800
Subject: Change API angular.compile(element)([scope], [element/true])
---
test/BinderSpec.js | 110 ++++++++++++++++++++++++++---------------------------
1 file changed, 54 insertions(+), 56 deletions(-)
(limited to 'test/BinderSpec.js')
diff --git a/test/BinderSpec.js b/test/BinderSpec.js
index c3f90ad7..a1b9be14 100644
--- a/test/BinderSpec.js
+++ b/test/BinderSpec.js
@@ -4,7 +4,6 @@ describe('Binder', function(){
var self = this;
this.compile = function(html, parent) {
- var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
if (self.element) dealoc(self.element);
var element;
if (parent) {
@@ -14,11 +13,10 @@ describe('Binder', function(){
element = jqLite(html);
}
self.element = element;
- var scope = compiler.compile(element)(element);
- return {node:element, scope:scope};
+ return angular.compile(element)();
};
this.compileToHtml = function (content) {
- return sortedHtml(this.compile(content).node);
+ return sortedHtml(this.compile(content).view);
};
});
@@ -92,7 +90,7 @@ describe('Binder', function(){
var form = this.compile('
x
');
form.scope.$set('model', {a:123});
form.scope.$eval();
- assertEquals('123', form.node.text());
+ assertEquals('123', form.view.text());
});
it('ReplaceBindingInTextWithSpan', function(){
@@ -115,7 +113,7 @@ describe('Binder', function(){
it('BindingOfAttributes', function(){
var c = this.compile("");
- var attrbinding = c.node.attr("ng:bind-attr");
+ var attrbinding = c.view.attr("ng:bind-attr");
var bindings = fromJson(attrbinding);
assertEquals("http://s/a{{b}}c", decodeURI(bindings.href));
assertTrue(!bindings.foo);
@@ -123,7 +121,7 @@ describe('Binder', function(){
it('MarkMultipleAttributes', function(){
var c = this.compile('');
- var attrbinding = c.node.attr("ng:bind-attr");
+ var attrbinding = c.view.attr("ng:bind-attr");
var bindings = fromJson(attrbinding);
assertEquals(bindings.foo, "{{d}}");
assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c");
@@ -131,23 +129,23 @@ describe('Binder', function(){
it('AttributesNoneBound', function(){
var c = this.compile("");
- var a = c.node;
+ var a = c.view;
assertEquals(a[0].nodeName, "A");
assertTrue(!a.attr("ng:bind-attr"));
});
it('ExistingAttrbindingIsAppended', function(){
var c = this.compile("");
- var a = c.node;
+ var a = c.view;
assertEquals('{"b":"{{def}}","href":"http://s/{{abc}}"}', a.attr('ng:bind-attr'));
});
it('AttributesAreEvaluated', function(){
var c = this.compile('');
- var binder = c.binder, form = c.node;
+ var binder = c.binder, form = c.view;
c.scope.$eval('a=1;b=2');
c.scope.$eval();
- var a = c.node;
+ var a = c.view;
assertEquals(a.attr('a'), 'a');
assertEquals(a.attr('b'), 'a+b=3');
});
@@ -158,7 +156,7 @@ describe('Binder', function(){
c.scope.$set("person.save", function(){
savedCalled = true;
});
- browserTrigger(c.node, 'click');
+ browserTrigger(c.view, 'click');
assertTrue(savedCalled);
});
@@ -169,7 +167,7 @@ describe('Binder', function(){
log += 'click;';
});
expect(log).toEqual('');
- browserTrigger(c.node, 'click');
+ browserTrigger(c.view, 'click');
expect(log).toEqual('click;');
});
@@ -179,13 +177,13 @@ describe('Binder', function(){
c.scope.$set("person.save", function(){
savedCalled = true;
});
- browserTrigger(c.node, 'click');
+ browserTrigger(c.view, 'click');
assertTrue(savedCalled);
});
it('RepeaterUpdateBindings', function(){
var a = this.compile('
');
- var form = a.node;
+ var form = a.view;
var items = [{a:"A"}, {a:"B"}];
a.scope.$set('model', {items:items});
@@ -225,7 +223,7 @@ describe('Binder', function(){
assertEquals('
' +
'<#comment>#comment>' +
'
A
' +
- '
', sortedHtml(a.node));
+ '', sortedHtml(a.view));
});
it('ExpandEntityTag', function(){
@@ -241,11 +239,11 @@ describe('Binder', function(){
it('RepeaterAdd', function(){
var c = this.compile('');
- var doc = c.node;
+ var doc = c.view;
c.scope.$set('items', [{x:'a'}, {x:'b'}]);
c.scope.$eval();
- var first = childNode(c.node, 1);
- var second = childNode(c.node, 2);
+ var first = childNode(c.view, 1);
+ var second = childNode(c.view, 2);
assertEquals('a', first.val());
assertEquals('b', second.val());
@@ -261,20 +259,20 @@ describe('Binder', function(){
c.scope.$set("items", items);
c.scope.$eval();
- expect(c.node[0].childNodes.length - 1).toEqual(0);
+ expect(c.view[0].childNodes.length - 1).toEqual(0);
items.name = "misko";
c.scope.$eval();
- expect(c.node[0].childNodes.length - 1).toEqual(1);
+ expect(c.view[0].childNodes.length - 1).toEqual(1);
delete items.name;
c.scope.$eval();
- expect(c.node[0].childNodes.length - 1).toEqual(0);
+ expect(c.view[0].childNodes.length - 1).toEqual(0);
});
it('IfTextBindingThrowsErrorDecorateTheSpan', function(){
var a = this.compile('
{{error.throw()}}
');
- var doc = a.node;
+ var doc = a.view;
var errorLogs = a.scope.$service('$log').error.logs;
a.scope.$set('error.throw', function(){throw "ErrorMsg1";});
@@ -303,7 +301,7 @@ describe('Binder', function(){
it('IfAttrBindingThrowsErrorDecorateTheAttribute', function(){
var a = this.compile('');
- var doc = a.node;
+ var doc = a.view;
var errorLogs = a.scope.$service('$log').error.logs;
a.scope.$set('error.throw', function(){throw "ErrorMsg";});
@@ -340,7 +338,7 @@ describe('Binder', function(){
'<#comment>#comment>'+
'
', sortedHtml(c.view));
});
it('FillInOptionValueWhenMissing', function(){
@@ -503,9 +501,9 @@ describe('Binder', function(){
c.scope.$set('a', 'A');
c.scope.$set('b', 'B');
c.scope.$eval();
- var optionA = childNode(c.node, 0);
- var optionB = childNode(c.node, 1);
- var optionC = childNode(c.node, 2);
+ var optionA = childNode(c.view, 0);
+ var optionB = childNode(c.view, 1);
+ var optionC = childNode(c.view, 2);
expect(optionA.attr('value')).toEqual('A');
expect(optionA.text()).toEqual('A');
@@ -565,7 +563,7 @@ describe('Binder', function(){
'');
c.scope.$eval();
function assertChild(index, disabled) {
- var child = childNode(c.node, index);
+ var child = childNode(c.view, index);
assertEquals(sortedHtml(child), disabled, !!child.attr('disabled'));
}
@@ -581,8 +579,8 @@ describe('Binder', function(){
var c = this.compile('
' +
'' +
'
');
- var first = jqLite(c.node[0].childNodes[0]);
- var second = jqLite(c.node[0].childNodes[1]);
+ var first = jqLite(c.view[0].childNodes[0]);
+ var second = jqLite(c.view[0].childNodes[1]);
var errorLogs = c.scope.$service('$log').error.logs;
browserTrigger(first, 'click');
@@ -598,8 +596,8 @@ describe('Binder', function(){
var c = this.compile('
' +
'' +
'
');
- var female = jqLite(c.node[0].childNodes[0]);
- var male = jqLite(c.node[0].childNodes[1]);
+ var female = jqLite(c.view[0].childNodes[0]);
+ var male = jqLite(c.view[0].childNodes[1]);
browserTrigger(female);
assertEquals("female", c.scope.sex);
@@ -636,7 +634,7 @@ describe('Binder', function(){
'