', sortedHtml(a.node));
};
BinderTest.prototype.testHideBindingExpression = function() {
var a = this.compile('');
a.scope.$set('hidden', 3);
a.scope.$eval();
assertHidden(a.node);
a.scope.$set('hidden', 2);
a.scope.$eval();
assertVisible(a.node);
};
BinderTest.prototype.testHideBinding = function() {
var c = this.compile('');
c.scope.$set('hidden', 'true');
c.scope.$eval();
assertHidden(c.node);
c.scope.$set('hidden', 'false');
c.scope.$eval();
assertVisible(c.node);
c.scope.$set('hidden', '');
c.scope.$eval();
assertVisible(c.node);
};
BinderTest.prototype.testShowBinding = function() {
var c = this.compile('');
c.scope.$set('show', 'true');
c.scope.$eval();
assertVisible(c.node);
c.scope.$set('show', 'false');
c.scope.$eval();
assertHidden(c.node);
c.scope.$set('show', '');
c.scope.$eval();
assertHidden(c.node);
};
BinderTest.prototype.testBindClassUndefined = function() {
var doc = this.compile('');
doc.scope.$eval();
assertEquals(
'',
sortedHtml(doc.node));
};
BinderTest.prototype.testBindClass = function() {
var c = this.compile('');
c.scope.$set('class', 'testClass');
c.scope.$eval();
assertEquals('', sortedHtml(c.node));
c.scope.$set('class', ['a', 'b']);
c.scope.$eval();
assertEquals('', sortedHtml(c.node));
};
BinderTest.prototype.testBindClassEvenOdd = function() {
var x = this.compile('
');
x.scope.$eval();
var d1 = jqLite(x.node[0].childNodes[1]);
var d2 = jqLite(x.node[0].childNodes[2]);
expect(d1.hasClass('o')).toBeTruthy();
expect(d2.hasClass('e')).toBeTruthy();
assertEquals(
'
<#comment>#comment>' +
'' +
'
',
sortedHtml(x.node));
};
BinderTest.prototype.testBindStyle = function() {
var c = this.compile('');
c.scope.$eval('style={color:"red"}');
c.scope.$eval();
assertEquals("red", c.node.css('color'));
c.scope.$eval('style={}');
c.scope.$eval();
};
BinderTest.prototype.testActionOnAHrefThrowsError = function(){
var model = {books:[]};
var c = this.compile('Add Phone', model);
c.scope.action = function(){
throw {a:'abc', b:2};
};
var input = c.node;
browserTrigger(input, 'click');
var error = fromJson(input.attr('ng-exception'));
assertEquals("abc", error.a);
assertEquals(2, error.b);
assertTrue("should have an error class", input.hasClass('ng-exception'));
// TODO: I think that exception should never get cleared so this portion of test makes no sense
//c.scope.action = noop;
//browserTrigger(input, 'click');
//dump(input.attr('ng-error'));
//assertFalse('error class should be cleared', input.hasClass('ng-exception'));
};
BinderTest.prototype.testShoulIgnoreVbNonBindable = function(){
var c = this.compile("
{{a}}" +
"
{{a}}
" +
"
{{b}}
" +
"
{{c}}
");
c.scope.$set('a', 123);
c.scope.$eval();
assertEquals('123{{a}}{{b}}{{c}}', c.node.text());
};
BinderTest.prototype.testOptionShouldUpdateParentToGetProperBinding = function() {
var c = this.compile('');
c.scope.$set('s', 1);
c.scope.$eval();
assertEquals(1, c.node[0].selectedIndex);
};
BinderTest.prototype.testRepeaterShouldBindInputsDefaults = function () {
var c = this.compile('');
c.scope.$set('items', [{}, {name:'misko'}]);
c.scope.$eval();
assertEquals("123", c.scope.$eval('items[0].name'));
assertEquals("misko", c.scope.$eval('items[1].name'));
};
BinderTest.prototype.testShouldTemplateBindPreElements = function () {
var c = this.compile('
');
c.scope.$eval();
function assertChild(index, disabled) {
var child = childNode(c.node, index);
assertEquals(sortedHtml(child), disabled, !!child.attr('disabled'));
}
assertChild(0, true);
assertChild(1, false);
assertChild(2, true);
assertChild(3, false);
assertChild(4, true);
assertChild(5, false);
};
BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){
var c = this.compile('
' +
'' +
'
');
var first = jqLite(c.node[0].childNodes[0]);
var second = jqLite(c.node[0].childNodes[1]);
browserTrigger(first, 'click');
assertEquals("ABC", c.scope.greeting);
browserTrigger(second, 'click');
assertTrue(second.hasClass("ng-exception"));
};
BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() {
var c = this.compile('
' +
'' +
'
');
var female = jqLite(c.node[0].childNodes[0]);
var male = jqLite(c.node[0].childNodes[1]);
browserTrigger(female);
assertEquals("female", c.scope.sex);
assertEquals(true, female[0].checked);
assertEquals(false, male[0].checked);
assertEquals("female", female.val());
browserTrigger(male);
assertEquals("male", c.scope.sex);
assertEquals(false, female[0].checked);
assertEquals(true, male[0].checked);
assertEquals("male", male.val());
};
BinderTest.prototype.testItShouldListenOnRightScope = function() {
var c = this.compile(
'