aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CompilerSpec.js9
-rw-r--r--test/directivesSpec.js12
-rw-r--r--test/markupSpec.js49
3 files changed, 64 insertions, 6 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js
index 57b597c4..a49a2551 100644
--- a/test/CompilerSpec.js
+++ b/test/CompilerSpec.js
@@ -3,7 +3,7 @@ describe('compiler', function(){
return jQuery(html)[0];
}
- var compiler, markup, directives, widgets, compile, log;
+ var compiler, textMarkup, directives, widgets, compile, log;
beforeEach(function(){
log = "";
@@ -24,9 +24,10 @@ describe('compiler', function(){
}
};
- markup = [];
+ textMarkup = [];
+ attrMarkup = [];
widgets = {};
- compiler = new Compiler(markup, directives, widgets);
+ compiler = new Compiler(textMarkup, attrMarkup, directives, widgets);
compile = function(html){
var e = element("<div>" + html + "</div>");
var view = compiler.compile(e)(e);
@@ -108,7 +109,7 @@ describe('compiler', function(){
});
it('should process markup before directives', function(){
- markup.push(function(text, textNode, parentNode) {
+ textMarkup.push(function(text, textNode, parentNode) {
if (text == 'middle') {
expect(textNode.text()).toEqual(text);
parentNode.attr('hello', text);
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
index d125d326..18bedb64 100644
--- a/test/directivesSpec.js
+++ b/test/directivesSpec.js
@@ -3,7 +3,7 @@ describe("directives", function(){
var compile, element;
beforeEach(function() {
- var compiler = new Compiler(angularMarkup, angularDirective, angularWidget);
+ var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
compile = function(html) {
element = jqLite(html);
var view = compiler.compile(element)(element);
@@ -39,6 +39,14 @@ describe("directives", function(){
expect(element.text()).toEqual('misko');
});
+ it('should ng-bind-template', function() {
+ var scope = compile('<div ng-bind-template="Hello {{name}}!"></div>');
+ expect(element.text()).toEqual('');
+ scope.set('name', 'Misko');
+ scope.updateView();
+ expect(element.text()).toEqual('Hello Misko!');
+ });
+
it('should ng-bind-attr', function(){
var scope = compile('<img ng-bind-attr="{src:\'mysrc\', alt:\'myalt\'}"/>');
expect(element.attr('src')).toEqual(null);
@@ -81,7 +89,7 @@ describe("directives", function(){
it('should error on wrong parsing of ng-repeat', function(){
var scope = compile('<ul><li ng-repeat="i dont parse"></li></ul>');
var log = "";
- element.eachNode(function(li){
+ eachNode(element, function(li){
log += li.attr('ng-error') + ';';
log += li.hasClass('ng-exception') + ';';
});
diff --git a/test/markupSpec.js b/test/markupSpec.js
new file mode 100644
index 00000000..9e89af7b
--- /dev/null
+++ b/test/markupSpec.js
@@ -0,0 +1,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");
+ });
+
+});