From bb98ae14f2aef74efbd8345e93f62ac67f460f7f Mon Sep 17 00:00:00 2001
From: Misko Hevery
Date: Tue, 23 Mar 2010 14:57:11 -0700
Subject: markup now wroks, some refactorings
---
test/CompilerSpec.js | 9 +++++----
test/directivesSpec.js | 12 ++++++++++--
test/markupSpec.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 6 deletions(-)
create mode 100644 test/markupSpec.js
(limited to 'test')
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("
" + html + "
");
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('');
+ 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('
');
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('');
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('hello {{name}}!
');
+ expect(element.html()).toEqual('hello !');
+ scope.set('name', 'Misko');
+ scope.updateView();
+ expect(element.html()).toEqual('hello Misko!');
+ });
+
+ it('should translate {{}} in terminal nodes', function(){
+ compile('');
+ expect(element.html()).toEqual('');
+ scope.set('name', 'Misko');
+ scope.updateView();
+ expect(element.html()).toEqual('');
+ });
+
+ it('should translate {{}} in attributes', function(){
+ compile('
');
+ 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");
+ });
+
+});
--
cgit v1.2.3