');
expect(scope.$element.text()).toEqual('-0false');
});
});
describe('ng:bind-template', function(){
it('should ng:bind-template', function() {
var scope = compile('');
scope.$set('name', 'Misko');
scope.$eval();
expect(element.hasClass('ng-binding')).toEqual(true);
expect(element.text()).toEqual('Hello Misko!');
});
it('should have $element set to current bind element', function(){
var innerText = 'blank';
angularFilter.myFilter = function(text){
innerText = this.$element.text();
return text;
};
var scope = compile('
beforeINNERafter
');
expect(scope.$element.text()).toEqual("beforeHELLOafter");
expect(innerText).toEqual('INNER');
});
});
describe('ng:bind-attr', function(){
it('should bind attributes', function(){
var scope = compile('');
expect(element.attr('src')).toEqual('http://localhost/mysrc');
expect(element.attr('alt')).toEqual('myalt');
});
it('should not pretty print JSON in attributes', function(){
var scope = compile('');
expect(element.attr('alt')).toEqual('{"a":1}');
});
});
it('should remove special attributes on false', function(){
var scope = compile('');
var input = scope.$element[0];
expect(input.disabled).toEqual(false);
expect(input.readOnly).toEqual(false);
expect(input.checked).toEqual(false);
scope.disabled = true;
scope.readonly = true;
scope.checked = true;
scope.$eval();
expect(input.disabled).toEqual(true);
expect(input.readOnly).toEqual(true);
expect(input.checked).toEqual(true);
});
describe('ng:click', function(){
it('should get called on a click', function(){
var scope = compile('');
scope.$eval();
expect(scope.$get('clicked')).toBeFalsy();
browserTrigger(element, 'click');
expect(scope.$get('clicked')).toEqual(true);
});
it('should stop event propagation', function() {
var scope = compile('
');
scope.$eval();
expect(scope.outer).not.toBeDefined();
expect(scope.inner).not.toBeDefined();
var innerDiv = element.children()[0];
browserTrigger(innerDiv, 'click');
expect(scope.outer).not.toBeDefined();
expect(scope.inner).toEqual(true);
});
});
describe('ng:submit', function() {
it('should get called on form submit', function() {
var scope = compile('');
scope.$eval();
expect(scope.submitted).not.toBeDefined();
browserTrigger(element.children()[0]);
expect(scope.submitted).toEqual(true);
});
});
describe('ng:class', function() {
it('should add new and remove old classes dynamically', function() {
var scope = compile('');
scope.dynClass = 'A';
scope.$eval();
expect(element.hasClass('existing')).toBe(true);
expect(element.hasClass('A')).toBe(true);
scope.dynClass = 'B';
scope.$eval();
expect(element.hasClass('existing')).toBe(true);
expect(element.hasClass('A')).toBe(false);
expect(element.hasClass('B')).toBe(true);
delete scope.dynClass;
scope.$eval();
expect(element.hasClass('existing')).toBe(true);
expect(element.hasClass('A')).toBe(false);
expect(element.hasClass('B')).toBe(false);
});
it('should support adding multiple classes', function(){
var scope = compile('');
scope.$eval();
expect(element.hasClass('existing')).toBeTruthy();
expect(element.hasClass('A')).toBeTruthy();
expect(element.hasClass('B')).toBeTruthy();
});
});
it('should ng:class odd/even', function(){
var scope = compile('
');
scope.$eval();
var e1 = jqLite(element[0].childNodes[1]);
var e2 = jqLite(element[0].childNodes[2]);
expect(e1.hasClass('existing')).toBeTruthy();
expect(e1.hasClass('odd')).toBeTruthy();
expect(e2.hasClass('existing')).toBeTruthy();
expect(e2.hasClass('even')).toBeTruthy();
});
it('should allow both ng:class and ng:class-odd/even on the same element', function() {
var scope = compile('
' +
'' +
'
');
scope.$eval();
var e1 = jqLite(element[0].childNodes[1]);
var e2 = jqLite(element[0].childNodes[2]);
expect(e1.hasClass('plainClass')).toBeTruthy();
expect(e1.hasClass('odd')).toBeTruthy();
expect(e1.hasClass('even')).toBeFalsy();
expect(e2.hasClass('plainClass')).toBeTruthy();
expect(e2.hasClass('even')).toBeTruthy();
expect(e2.hasClass('odd')).toBeFalsy();
});
it('should allow both ng:class and ng:class-odd/even with multiple classes', function() {
var scope = compile('