aboutsummaryrefslogtreecommitdiffstats
path: root/test/markupSpec.js
blob: 9e89af7b4806474b6c6cde97f09608d404dd15fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
describe("markups", function(){

  var compile, element, scope;

  beforeEach(function() {
    scope = null;
    element = null;
    var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
    compile = function(html) {
      element = jqLite(html);
      var view = compiler.compile(element)(element);
      view.init();
      scope = view.scope;
    };
  });

  afterEach(function(){
    if (element) {
      element.remove();
    }
    expect(_(jqCache).size()).toEqual(0);
  });

  it('should translate {{}} in text', function(){
    compile('<div>hello {{name}}!</div>');
    expect(element.html()).toEqual('hello <span ng-bind="name"></span>!');
    scope.set('name', 'Misko');
    scope.updateView();
    expect(element.html()).toEqual('hello <span ng-bind="name">Misko</span>!');
  });

  it('should translate {{}} in terminal nodes', function(){
    compile('<select><option>Greet {{name}}!</option></select>');
    expect(element.html()).toEqual('<option ng-bind-template="Greet {{name}}!"></option>');
    scope.set('name', 'Misko');
    scope.updateView();
    expect(element.html()).toEqual('<option ng-bind-template="Greet {{name}}!">Greet Misko!</option>');
  });

  it('should translate {{}} in attributes', function(){
    compile('<img src="http://server/{{path}}.png"/>');
    expect(element.attr('src')).toEqual();
    expect(element.attr('ng-bind-attr')).toEqual('{"src":"http://server/{{path}}.png"}');
    scope.set('path', 'a/b');
    scope.updateView();
    expect(element.attr('src')).toEqual("http://server/a/b.png");
  });

});