describe("directives", function(){
  var compile, model, element;
  beforeEach(function() {
    var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
    compile = function(html) {
      element = jqLite(html);
      model = compiler.compile(element)(element);
      model.$init();
      return model;
    };
  });
  afterEach(function() {
    if (model && model.$element) model.$element.remove();
    expect(size(jqCache)).toEqual(0);
  });
  it("should ng:init", function() {
    var scope = compile('
');
    expect(scope.a).toEqual(123);
  });
  it("should ng:eval", function() {
    var scope = compile('
');
    expect(scope.a).toEqual(1);
    scope.$eval();
    expect(scope.a).toEqual(2);
  });
  describe('ng:bind', function(){
    it('should set text', function() {
      var scope = compile('
');
      expect(element.text()).toEqual('');
      scope.a = 'misko';
      scope.$eval();
      expect(element.text()).toEqual('misko');
    });
    it('should set text to blank if undefined', function() {
      var scope = compile('
');
      scope.a = 'misko';
      scope.$eval();
      expect(element.text()).toEqual('misko');
      scope.a = undefined;
      scope.$eval();
      expect(element.text()).toEqual('');
    });
    it('should set html', function() {
      var scope = compile('
');
      scope.html = 'hello
';
      scope.$eval();
      expect(lowercase(element.html())).toEqual('hello
');
    });
    it('should set element element', function() {
      angularFilter.myElement = function() {
        return jqLite('hello ');
      };
      var scope = compile('
');
      scope.$eval();
      expect(lowercase(element.html())).toEqual('hello ');
    });
    it('should have $element set to current bind element', function(){
      angularFilter.myFilter = function(){
        this.$element.addClass("filter");
        return 'HELLO';
      };
      var scope = compile('');
      expect(sortedHtml(scope.$element)).toEqual('');
    });
  });
  describe('ng:bind-template', function(){
    it('should ng:bind-template', function() {
      var scope = compile('
');
      scope.$set('name', 'Misko');
      scope.$eval();
      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('beforeINNER after
');
      expect(scope.$element.text()).toEqual("beforeHELLOafter");
      expect(innerText).toEqual('INNER');
    });
  });
  it('should ng:bind-attr', function(){
    var scope = compile(' ');
    expect(element.attr('src')).toEqual('http://localhost/mysrc');
    expect(element.attr('alt')).toEqual('myalt');
  });
  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);
  });
  it('should ng:non-bindable', function(){
    var scope = compile('
');
    scope.$set('name', 'misko');
    scope.$eval();
    expect(element.text()).toEqual('');
  });
  it('should ng:repeat over array', function(){
    var scope = compile('');
    Array.prototype.extraProperty = "should be ignored";
    scope.items = ['misko', 'shyam'];
    scope.$eval();
    expect(element.text()).toEqual('misko;shyam;');
    delete Array.prototype.extraProperty;
    scope.items = ['adam', 'kai', 'brad'];
    scope.$eval();
    expect(element.text()).toEqual('adam;kai;brad;');
    scope.items = ['brad'];
    scope.$eval();
    expect(element.text()).toEqual('brad;');
  });
  it('should ng:repeat over object', function(){
    var scope = compile('');
    scope.$set('items', {misko:'swe', shyam:'set'});
    scope.$eval();
    expect(element.text()).toEqual('misko:swe;shyam:set;');
  });
  it('should error on wrong parsing of ng:repeat', function(){
    var scope = compile('');
    var log = "";
    log += element.attr('ng-exception') + ';';
    log += element.hasClass('ng-exception') + ';';
    expect(log).toEqual("\"Expected ng:repeat in form of 'item in collection' but got 'i dont parse'.\";true;");
  });
  it('should ng:watch', function(){
    var scope = compile('');
    scope.$eval();
    scope.$eval();
    expect(scope.$get('count')).toEqual(0);
    scope.$set('i', 0);
    scope.$eval();
    scope.$eval();
    expect(scope.$get('count')).toEqual(1);
  });
  describe('ng:click', function(){
    it('should fire event', function(){
      var scope = compile('
');
      scope.$eval();
      expect(scope.$get('clicked')).toBeFalsy();
      element.trigger('click');
      expect(scope.$get('clicked')).toEqual(true);
    });
    it('should stop event propagation', function() {
      var scope = compile('
');
      scope.$eval();
      expect(scope.$get('outer')).not.toBeDefined();
      expect(scope.$get('inner')).not.toBeDefined();
      var innerDiv = jqLite(element.children()[0]);
      innerDiv.trigger('click');
      expect(scope.$get('outer')).not.toBeDefined();
      expect(scope.$get('inner')).toEqual(true);
    });
  });
  it('should ng:class', 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('