');
+ assertEquals(scope.$get('a'), 123);
});
it('ExecuteInitializationStatements', function(){
- var c = this.compile('
');
- assertEquals(c.scope.$get('a'), 123);
- assertEquals(c.scope.$get('b'), 345);
+ var scope = this.compile('
');
+ assertEquals(scope.$get('a'), 123);
+ assertEquals(scope.$get('b'), 345);
});
it('ApplyTextBindings', function(){
- var form = this.compile('
x
');
- form.scope.$set('model', {a:123});
- form.scope.$eval();
- assertEquals('123', form.view.text());
+ var scope = this.compile('
x
');
+ scope.$set('model', {a:123});
+ scope.$eval();
+ assertEquals('123', scope.$element.text());
});
it('ReplaceBindingInTextWithSpan', function(){
@@ -112,82 +112,81 @@ describe('Binder', function(){
});
it('BindingOfAttributes', function(){
- var c = this.compile("
");
- var attrbinding = c.view.attr("ng:bind-attr");
+ var scope = this.compile("
");
+ var attrbinding = scope.$element.attr("ng:bind-attr");
var bindings = fromJson(attrbinding);
assertEquals("http://s/a{{b}}c", decodeURI(bindings.href));
assertTrue(!bindings.foo);
});
it('MarkMultipleAttributes', function(){
- var c = this.compile('
');
- var attrbinding = c.view.attr("ng:bind-attr");
+ var scope = this.compile('
');
+ var attrbinding = scope.$element.attr("ng:bind-attr");
var bindings = fromJson(attrbinding);
assertEquals(bindings.foo, "{{d}}");
assertEquals(decodeURI(bindings.href), "http://s/a{{b}}c");
});
it('AttributesNoneBound', function(){
- var c = this.compile("
");
- var a = c.view;
+ var scope = this.compile("
");
+ var a = scope.$element;
assertEquals(a[0].nodeName, "A");
assertTrue(!a.attr("ng:bind-attr"));
});
it('ExistingAttrbindingIsAppended', function(){
- var c = this.compile("
");
- var a = c.view;
+ var scope = this.compile("
");
+ var a = scope.$element;
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.view;
- c.scope.$eval('a=1;b=2');
- c.scope.$eval();
- var a = c.view;
+ var scope = this.compile('
');
+ scope.$eval('a=1;b=2');
+ scope.$eval();
+ var a = scope.$element;
assertEquals(a.attr('a'), 'a');
assertEquals(a.attr('b'), 'a+b=3');
});
it('InputTypeButtonActionExecutesInScope', function(){
var savedCalled = false;
- var c = this.compile('
');
- c.scope.$set("person.save", function(){
+ var scope = this.compile('
');
+ scope.$set("person.save", function(){
savedCalled = true;
});
- browserTrigger(c.view, 'click');
+ browserTrigger(scope.$element, 'click');
assertTrue(savedCalled);
});
it('InputTypeButtonActionExecutesInScope2', function(){
var log = "";
- var c = this.compile('
');
- c.scope.$set("action", function(){
+ var scope = this.compile('
');
+ scope.$set("action", function(){
log += 'click;';
});
expect(log).toEqual('');
- browserTrigger(c.view, 'click');
+ browserTrigger(scope.$element, 'click');
expect(log).toEqual('click;');
});
it('ButtonElementActionExecutesInScope', function(){
var savedCalled = false;
- var c = this.compile('
Apply ');
- c.scope.$set("person.save", function(){
+ var scope = this.compile('
Apply ');
+ scope.$set("person.save", function(){
savedCalled = true;
});
- browserTrigger(c.view, 'click');
+ browserTrigger(scope.$element, 'click');
assertTrue(savedCalled);
});
it('RepeaterUpdateBindings', function(){
- var a = this.compile('
');
- var form = a.view;
+ var scope = this.compile('
');
+ var form = scope.$element;
var items = [{a:"A"}, {a:"B"}];
- a.scope.$set('model', {items:items});
+ scope.$set('model', {items:items});
- a.scope.$eval();
+ scope.$eval();
assertEquals('
' +
'<#comment>#comment>' +
'A ' +
@@ -195,7 +194,7 @@ describe('Binder', function(){
' ', sortedHtml(form));
items.unshift({a:'C'});
- a.scope.$eval();
+ scope.$eval();
assertEquals('
' +
'<#comment>#comment>' +
'C ' +
@@ -204,7 +203,7 @@ describe('Binder', function(){
' ', sortedHtml(form));
items.shift();
- a.scope.$eval();
+ scope.$eval();
assertEquals('
' +
'<#comment>#comment>' +
'A ' +
@@ -213,17 +212,17 @@ describe('Binder', function(){
items.shift();
items.shift();
- a.scope.$eval();
+ scope.$eval();
});
it('RepeaterContentDoesNotBind', function(){
- var a = this.compile('');
- a.scope.$set('model', {items:[{a:"A"}]});
- a.scope.$eval();
+ var scope = this.compile('');
+ scope.$set('model', {items:[{a:"A"}]});
+ scope.$eval();
assertEquals('' +
'<#comment>#comment>' +
'A ' +
- ' ', sortedHtml(a.view));
+ ' ', sortedHtml(scope.$element));
});
it('DoNotOverwriteCustomAction', function(){
@@ -232,61 +231,60 @@ describe('Binder', function(){
});
it('RepeaterAdd', function(){
- var c = this.compile('
');
- var doc = c.view;
- c.scope.$set('items', [{x:'a'}, {x:'b'}]);
- c.scope.$eval();
- var first = childNode(c.view, 1);
- var second = childNode(c.view, 2);
+ var scope = this.compile('
');
+ scope.$set('items', [{x:'a'}, {x:'b'}]);
+ scope.$eval();
+ var first = childNode(scope.$element, 1);
+ var second = childNode(scope.$element, 2);
assertEquals('a', first.val());
assertEquals('b', second.val());
first.val('ABC');
browserTrigger(first, 'keydown');
- c.scope.$service('$browser').defer.flush();
- assertEquals(c.scope.items[0].x, 'ABC');
+ scope.$service('$browser').defer.flush();
+ assertEquals(scope.items[0].x, 'ABC');
});
it('ItShouldRemoveExtraChildrenWhenIteratingOverHash', function(){
- var c = this.compile('
');
+ var scope = this.compile('
');
var items = {};
- c.scope.$set("items", items);
+ scope.$set("items", items);
- c.scope.$eval();
- expect(c.view[0].childNodes.length - 1).toEqual(0);
+ scope.$eval();
+ expect(scope.$element[0].childNodes.length - 1).toEqual(0);
items.name = "misko";
- c.scope.$eval();
- expect(c.view[0].childNodes.length - 1).toEqual(1);
+ scope.$eval();
+ expect(scope.$element[0].childNodes.length - 1).toEqual(1);
delete items.name;
- c.scope.$eval();
- expect(c.view[0].childNodes.length - 1).toEqual(0);
+ scope.$eval();
+ expect(scope.$element[0].childNodes.length - 1).toEqual(0);
});
it('IfTextBindingThrowsErrorDecorateTheSpan', function(){
- var a = this.compile('
{{error.throw()}}
');
- var doc = a.view;
- var errorLogs = a.scope.$service('$log').error.logs;
+ var scope = this.compile('
{{error.throw()}}
');
+ var doc = scope.$element;
+ var errorLogs = scope.$service('$log').error.logs;
- a.scope.$set('error.throw', function(){throw "ErrorMsg1";});
- a.scope.$eval();
+ scope.$set('error.throw', function(){throw "ErrorMsg1";});
+ scope.$eval();
var span = childNode(doc, 0);
assertTrue(span.hasClass('ng-exception'));
assertTrue(!!span.text().match(/ErrorMsg1/));
assertTrue(!!span.attr('ng-exception').match(/ErrorMsg1/));
assertEquals(['ErrorMsg1'], errorLogs.shift());
- a.scope.$set('error.throw', function(){throw "MyError";});
- a.scope.$eval();
+ scope.$set('error.throw', function(){throw "MyError";});
+ scope.$eval();
span = childNode(doc, 0);
assertTrue(span.hasClass('ng-exception'));
assertTrue(span.text(), span.text().match('MyError') !== null);
assertEquals('MyError', span.attr('ng-exception'));
assertEquals(['MyError'], errorLogs.shift());
- a.scope.$set('error.throw', function(){return "ok";});
- a.scope.$eval();
+ scope.$set('error.throw', function(){return "ok";});
+ scope.$eval();
assertFalse(span.hasClass('ng-exception'));
assertEquals('ok', span.text());
assertEquals(null, span.attr('ng-exception'));
@@ -294,19 +292,19 @@ describe('Binder', function(){
});
it('IfAttrBindingThrowsErrorDecorateTheAttribute', function(){
- var a = this.compile('
');
- var doc = a.view;
- var errorLogs = a.scope.$service('$log').error.logs;
+ var scope = this.compile('
');
+ var doc = scope.$element;
+ var errorLogs = scope.$service('$log').error.logs;
- a.scope.$set('error.throw', function(){throw "ErrorMsg";});
- a.scope.$eval();
+ scope.$set('error.throw', function(){throw "ErrorMsg";});
+ scope.$eval();
assertTrue('ng-exception', doc.hasClass('ng-exception'));
assertEquals('"ErrorMsg"', doc.attr('ng-exception'));
assertEquals('before "ErrorMsg" after', doc.attr('attr'));
assertEquals(['ErrorMsg'], errorLogs.shift());
- a.scope.$set('error.throw', function(){ return 'X';});
- a.scope.$eval();
+ scope.$set('error.throw', function(){ return 'X';});
+ scope.$eval();
assertFalse('!ng-exception', doc.hasClass('ng-exception'));
assertEquals('before X after', doc.attr('attr'));
assertEquals(null, doc.attr('ng-exception'));
@@ -314,12 +312,12 @@ describe('Binder', function(){
});
it('NestedRepeater', function(){
- var a = this.compile('
' +
+ var scope = this.compile('
');
- a.scope.$set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]);
- a.scope.$eval();
+ scope.$set('model', [{name:'a', item:['a1', 'a2']}, {name:'b', item:['b1', 'b2']}]);
+ scope.$eval();
assertEquals('
'+
'<#comment>#comment>'+
@@ -332,121 +330,121 @@ describe('Binder', function(){
'<#comment>#comment>'+
'
'+
'
'+
- '
', sortedHtml(a.view));
+ '
', sortedHtml(scope.$element));
});
it('HideBindingExpression', function(){
- var a = this.compile('
');
+ var scope = this.compile('
');
- a.scope.$set('hidden', 3);
- a.scope.$eval();
+ scope.$set('hidden', 3);
+ scope.$eval();
- assertHidden(a.view);
+ assertHidden(scope.$element);
- a.scope.$set('hidden', 2);
- a.scope.$eval();
+ scope.$set('hidden', 2);
+ scope.$eval();
- assertVisible(a.view);
+ assertVisible(scope.$element);
});
it('HideBinding', function(){
- var c = this.compile('
');
+ var scope = this.compile('
');
- c.scope.$set('hidden', 'true');
- c.scope.$eval();
+ scope.$set('hidden', 'true');
+ scope.$eval();
- assertHidden(c.view);
+ assertHidden(scope.$element);
- c.scope.$set('hidden', 'false');
- c.scope.$eval();
+ scope.$set('hidden', 'false');
+ scope.$eval();
- assertVisible(c.view);
+ assertVisible(scope.$element);
- c.scope.$set('hidden', '');
- c.scope.$eval();
+ scope.$set('hidden', '');
+ scope.$eval();
- assertVisible(c.view);
+ assertVisible(scope.$element);
});
it('ShowBinding', function(){
- var c = this.compile('
');
+ var scope = this.compile('
');
- c.scope.$set('show', 'true');
- c.scope.$eval();
+ scope.$set('show', 'true');
+ scope.$eval();
- assertVisible(c.view);
+ assertVisible(scope.$element);
- c.scope.$set('show', 'false');
- c.scope.$eval();
+ scope.$set('show', 'false');
+ scope.$eval();
- assertHidden(c.view);
+ assertHidden(scope.$element);
- c.scope.$set('show', '');
- c.scope.$eval();
+ scope.$set('show', '');
+ scope.$eval();
- assertHidden(c.view);
+ assertHidden(scope.$element);
});
it('BindClassUndefined', function(){
- var doc = this.compile('
');
- doc.scope.$eval();
+ var scope = this.compile('
');
+ scope.$eval();
assertEquals(
'
',
- sortedHtml(doc.view));
+ sortedHtml(scope.$element));
});
it('BindClass', function(){
- var c = this.compile('
');
+ var scope = this.compile('
');
- c.scope.$set('class', 'testClass');
- c.scope.$eval();
+ scope.$set('class', 'testClass');
+ scope.$eval();
- assertEquals('
', sortedHtml(c.view));
+ assertEquals('
', sortedHtml(scope.$element));
- c.scope.$set('class', ['a', 'b']);
- c.scope.$eval();
+ scope.$set('class', ['a', 'b']);
+ scope.$eval();
- assertEquals('
', sortedHtml(c.view));
+ assertEquals('
', sortedHtml(scope.$element));
});
it('BindClassEvenOdd', function(){
- var x = this.compile('
');
- x.scope.$eval();
- var d1 = jqLite(x.view[0].childNodes[1]);
- var d2 = jqLite(x.view[0].childNodes[2]);
+ var scope = this.compile('
');
+ scope.$eval();
+ var d1 = jqLite(scope.$element[0].childNodes[1]);
+ var d2 = jqLite(scope.$element[0].childNodes[2]);
expect(d1.hasClass('o')).toBeTruthy();
expect(d2.hasClass('e')).toBeTruthy();
assertEquals(
'
<#comment>#comment>' +
'
' +
'
',
- sortedHtml(x.view));
+ sortedHtml(scope.$element));
});
it('BindStyle', function(){
- var c = this.compile('
');
+ var scope = this.compile('
');
- c.scope.$eval('style={color:"red"}');
- c.scope.$eval();
+ scope.$eval('style={color:"red"}');
+ scope.$eval();
- assertEquals("red", c.view.css('color'));
+ assertEquals("red", scope.$element.css('color'));
- c.scope.$eval('style={}');
- c.scope.$eval();
+ scope.$eval('style={}');
+ scope.$eval();
});
it('ActionOnAHrefThrowsError', function(){
- var c = this.compile('
Add Phone ');
- c.scope.action = function(){
+ var scope = this.compile('
Add Phone ');
+ scope.action = function(){
throw new Error('MyError');
};
- var input = c.view;
+ var input = scope.$element;
browserTrigger(input, 'click');
var error = input.attr('ng-exception');
assertTrue(!!error.match(/MyError/));
assertTrue("should have an error class", input.hasClass('ng-exception'));
- assertTrue(!!c.scope.$service('$log').error.logs.shift()[0].message.match(/MyError/));
+ assertTrue(!!scope.$service('$log').error.logs.shift()[0].message.match(/MyError/));
// TODO: I think that exception should never get cleared so this portion of test makes no sense
//c.scope.action = noop;
@@ -456,48 +454,48 @@ describe('Binder', function(){
});
it('ShoulIgnoreVbNonBindable', function(){
- var c = this.compile("
{{a}}" +
+ var scope = this.compile("
{{a}}" +
"
{{a}}
" +
"
{{b}}
" +
"
{{c}}
");
- c.scope.$set('a', 123);
- c.scope.$eval();
- assertEquals('123{{a}}{{b}}{{c}}', c.view.text());
+ scope.$set('a', 123);
+ scope.$eval();
+ assertEquals('123{{a}}{{b}}{{c}}', scope.$element.text());
});
it('OptionShouldUpdateParentToGetProperBinding', function(){
- var c = this.compile('
');
- c.scope.$set('s', 1);
- c.scope.$eval();
- assertEquals(1, c.view[0].selectedIndex);
+ var scope = this.compile('
');
+ scope.$set('s', 1);
+ scope.$eval();
+ assertEquals(1, scope.$element[0].selectedIndex);
});
it('RepeaterShouldBindInputsDefaults', function () {
- var c = this.compile('
');
- c.scope.$set('items', [{}, {name:'misko'}]);
- c.scope.$eval();
+ var scope = this.compile('
');
+ scope.$set('items', [{}, {name:'misko'}]);
+ scope.$eval();
- assertEquals("123", c.scope.$eval('items[0].name'));
- assertEquals("misko", c.scope.$eval('items[1].name'));
+ assertEquals("123", scope.$eval('items[0].name'));
+ assertEquals("misko", scope.$eval('items[1].name'));
});
it('ShouldTemplateBindPreElements', function () {
- var c = this.compile('
Hello {{name}}! ');
- c.scope.$set("name", "World");
- c.scope.$eval();
+ var scope = this.compile('
Hello {{name}}! ');
+ scope.$set("name", "World");
+ scope.$eval();
- assertEquals('
Hello World! ', sortedHtml(c.view));
+ assertEquals('
Hello World! ', sortedHtml(scope.$element));
});
it('FillInOptionValueWhenMissing', function(){
- var c = this.compile(
+ var scope = this.compile(
'
{{a}} {{b}} C ');
- c.scope.$set('a', 'A');
- c.scope.$set('b', 'B');
- c.scope.$eval();
- var optionA = childNode(c.view, 0);
- var optionB = childNode(c.view, 1);
- var optionC = childNode(c.view, 2);
+ scope.$set('a', 'A');
+ scope.$set('b', 'B');
+ scope.$eval();
+ var optionA = childNode(scope.$element, 0);
+ var optionB = childNode(scope.$element, 1);
+ var optionC = childNode(scope.$element, 2);
expect(optionA.attr('value')).toEqual('A');
expect(optionA.text()).toEqual('A');
@@ -510,54 +508,54 @@ describe('Binder', function(){
});
it('ValidateForm', function(){
- var c = this.compile('
' +
+ var scope = this.compile('
' +
'
',
jqLite(document.body));
var items = [{}, {}];
- c.scope.$set("items", items);
- c.scope.$eval();
- assertEquals(3, c.scope.$service('$invalidWidgets').length);
+ scope.$set("items", items);
+ scope.$eval();
+ assertEquals(3, scope.$service('$invalidWidgets').length);
- c.scope.$set('name', '');
- c.scope.$eval();
- assertEquals(3, c.scope.$service('$invalidWidgets').length);
+ scope.$set('name', '');
+ scope.$eval();
+ assertEquals(3, scope.$service('$invalidWidgets').length);
- c.scope.$set('name', ' ');
- c.scope.$eval();
- assertEquals(3, c.scope.$service('$invalidWidgets').length);
+ scope.$set('name', ' ');
+ scope.$eval();
+ assertEquals(3, scope.$service('$invalidWidgets').length);
- c.scope.$set('name', 'abc');
- c.scope.$eval();
- assertEquals(2, c.scope.$service('$invalidWidgets').length);
+ scope.$set('name', 'abc');
+ scope.$eval();
+ assertEquals(2, scope.$service('$invalidWidgets').length);
items[0].name = 'abc';
- c.scope.$eval();
- assertEquals(1, c.scope.$service('$invalidWidgets').length);
+ scope.$eval();
+ assertEquals(1, scope.$service('$invalidWidgets').length);
items[1].name = 'abc';
- c.scope.$eval();
- assertEquals(0, c.scope.$service('$invalidWidgets').length);
+ scope.$eval();
+ assertEquals(0, scope.$service('$invalidWidgets').length);
});
it('ValidateOnlyVisibleItems', function(){
- var c = this.compile('
', jqLite(document.body));
- c.scope.$set("show", true);
- c.scope.$eval();
- assertEquals(2, c.scope.$service('$invalidWidgets').length);
+ var scope = this.compile('
', jqLite(document.body));
+ scope.$set("show", true);
+ scope.$eval();
+ assertEquals(2, scope.$service('$invalidWidgets').length);
- c.scope.$set("show", false);
- c.scope.$eval();
- assertEquals(1, c.scope.$service('$invalidWidgets').visible());
+ scope.$set("show", false);
+ scope.$eval();
+ assertEquals(1, scope.$service('$invalidWidgets').visible());
});
it('DeleteAttributeIfEvaluatesFalse', function(){
- var c = this.compile('
' +
+ var scope = this.compile('
' +
' ' +
' ' +
'
');
- c.scope.$eval();
+ scope.$eval();
function assertChild(index, disabled) {
- var child = childNode(c.view, index);
+ var child = childNode(scope.$element, index);
assertEquals(sortedHtml(child), disabled, !!child.attr('disabled'));
}
@@ -570,15 +568,15 @@ describe('Binder', function(){
});
it('ItShouldDisplayErrorWhenActionIsSyntacticlyIncorrect', function(){
- var c = this.compile('
' +
+ var scope = this.compile('
' +
' ' +
'
');
- var first = jqLite(c.view[0].childNodes[0]);
- var second = jqLite(c.view[0].childNodes[1]);
- var errorLogs = c.scope.$service('$log').error.logs;
+ var first = jqLite(scope.$element[0].childNodes[0]);
+ var second = jqLite(scope.$element[0].childNodes[1]);
+ var errorLogs = scope.$service('$log').error.logs;
browserTrigger(first, 'click');
- assertEquals("ABC", c.scope.greeting);
+ assertEquals("ABC", scope.greeting);
expect(errorLogs).toEqual([]);
browserTrigger(second, 'click');
@@ -587,70 +585,70 @@ describe('Binder', function(){
});
it('ItShouldSelectTheCorrectRadioBox', function(){
- var c = this.compile('
' +
+ var scope = this.compile('
' +
' ' +
'
');
- var female = jqLite(c.view[0].childNodes[0]);
- var male = jqLite(c.view[0].childNodes[1]);
+ var female = jqLite(scope.$element[0].childNodes[0]);
+ var male = jqLite(scope.$element[0].childNodes[1]);
browserTrigger(female);
- assertEquals("female", c.scope.sex);
+ assertEquals("female", scope.sex);
assertEquals(true, female[0].checked);
assertEquals(false, male[0].checked);
assertEquals("female", female.val());
browserTrigger(male);
- assertEquals("male", c.scope.sex);
+ assertEquals("male", scope.sex);
assertEquals(false, female[0].checked);
assertEquals(true, male[0].checked);
assertEquals("male", male.val());
});
it('ItShouldRepeatOnHashes', function(){
- var x = this.compile('
');
- x.scope.$eval();
+ var scope = this.compile('
');
+ scope.$eval();
assertEquals('
' +
'<#comment>#comment>' +
'a0 ' +
'b1 ' +
' ',
- sortedHtml(x.view));
+ sortedHtml(scope.$element));
});
it('ItShouldFireChangeListenersBeforeUpdate', function(){
- var x = this.compile('
');
- x.scope.$set("name", "");
- x.scope.$watch("watched", "name=123");
- x.scope.$set("watched", "change");
- x.scope.$eval();
- assertEquals(123, x.scope.$get("name"));
+ var scope = this.compile('
');
+ scope.$set("name", "");
+ scope.$watch("watched", "name=123");
+ scope.$set("watched", "change");
+ scope.$eval();
+ assertEquals(123, scope.$get("name"));
assertEquals(
'
123
',
- sortedHtml(x.view));
+ sortedHtml(scope.$element));
});
it('ItShouldHandleMultilineBindings', function(){
- var x = this.compile('
{{\n 1 \n + \n 2 \n}}
');
- x.scope.$eval();
- assertEquals("3", x.view.text());
+ var scope = this.compile('
{{\n 1 \n + \n 2 \n}}
');
+ scope.$eval();
+ assertEquals("3", scope.$element.text());
});
it('ItBindHiddenInputFields', function(){
- var x = this.compile('
');
- x.scope.$eval();
- assertEquals("abc", x.scope.$get("myName"));
+ var scope = this.compile('
');
+ scope.$eval();
+ assertEquals("abc", scope.$get("myName"));
});
it('ItShouldUseFormaterForText', function(){
- var x = this.compile('
');
- x.scope.$eval();
- assertEquals(['a','b'], x.scope.$get('a'));
- var input = x.view;
+ var scope = this.compile('
');
+ scope.$eval();
+ assertEquals(['a','b'], scope.$get('a'));
+ var input = scope.$element;
input[0].value = ' x,,yz';
browserTrigger(input, 'change');
- assertEquals(['x','yz'], x.scope.$get('a'));
- x.scope.$set('a', [1 ,2, 3]);
- x.scope.$eval();
+ assertEquals(['x','yz'], scope.$get('a'));
+ scope.$set('a', [1 ,2, 3]);
+ scope.$eval();
assertEquals('1, 2, 3', input[0].value);
});
--
cgit v1.2.3