aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/CompilerSpec.js33
-rw-r--r--test/ParserTest.js19
-rw-r--r--test/directivesSpec.js71
3 files changed, 100 insertions, 23 deletions
diff --git a/test/CompilerSpec.js b/test/CompilerSpec.js
index 9f02262d..3ea2e473 100644
--- a/test/CompilerSpec.js
+++ b/test/CompilerSpec.js
@@ -36,7 +36,7 @@ describe('compiler', function(){
});
it('should recognize a directive', function(){
- var e = element('<div ng-directive="expr" ignore="me"></div>');
+ var e = element('<div directive="expr" ignore="me"></div>');
directives.directive = function(expression, element){
log += "found";
expect(expression).toEqual("expr");
@@ -53,12 +53,12 @@ describe('compiler', function(){
});
it('should recurse to children', function(){
- var scope = compile('<div><span ng-hello="misko"/></div>');
+ var scope = compile('<div><span hello="misko"/></div>');
expect(log).toEqual("hello misko");
});
it('should watch scope', function(){
- var scope = compile('<span ng-watch="name"/>');
+ var scope = compile('<span watch="name"/>');
expect(log).toEqual("");
scope.updateView();
scope.set('name', 'misko');
@@ -70,24 +70,24 @@ describe('compiler', function(){
expect(log).toEqual(":misko:adam");
});
- it('should prevent recursion', function(){
- directives.stop = function(){ return false; };
- var scope = compile('<span ng-hello="misko" ng-stop="true"><span ng-hello="adam"/></span>');
+ it('should prevent descend', function(){
+ directives.stop = function(){ this.descend(false); };
+ var scope = compile('<span hello="misko" stop="true"><span hello="adam"/></span>');
expect(log).toEqual("hello misko");
});
it('should allow creation of templates', function(){
directives.duplicate = function(expr, element){
element.replaceWith(document.createComment("marker"));
- element.removeAttribute("ng-duplicate");
+ element.removeAttr("duplicate");
var template = this.compile(element);
return function(marker) {
- this.$eval(function() {
+ this.$addEval(function() {
marker.after(template(element.clone()).element);
});
};
};
- var scope = compile('before<span ng-duplicate="expr">x</span>after');
+ var scope = compile('before<span duplicate="expr">x</span>after');
expect($(scope.element).html()).toEqual('before<!--marker-->after');
scope.updateView();
expect($(scope.element).html()).toEqual('before<!--marker--><span>x</span>after');
@@ -103,7 +103,7 @@ describe('compiler', function(){
};
directives.exclusive.exclusive = true;
- compile('<span ng-hello="misko", ng-exclusive/>');
+ compile('<span hello="misko", exclusive/>');
expect(log).toEqual('exclusive');
});
@@ -111,24 +111,25 @@ describe('compiler', function(){
markup.push(function(text, textNode, parentNode) {
if (text == 'middle') {
expect(textNode.text()).toEqual(text);
- parentNode.attr('ng-hello', text);
+ parentNode.attr('hello', text);
textNode.text('replaced');
}
});
var scope = compile('before<span>middle</span>after');
- expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after');
+ expect(scope.element.innerHTML).toEqual('before<span hello="middle">replaced</span>after');
expect(log).toEqual("hello middle");
});
- xit('should replace widgets', function(){
- widgets.button = function(element) {
- element.parentNode.replaceChild(button, element);
+ it('should replace widgets', function(){
+ widgets['NG:BUTTON'] = function(element) {
+ element.replaceWith('<div>button</div>', element);
return function(element) {
log += 'init';
};
};
var scope = compile('<ng:button>push me</ng:button>');
- expect(scope.element.innerHTML).toEqual('before<span ng-hello="middle">replaced</span>after');
+ expect(scope.element.innerHTML).toEqual('<div>button</div>');
+ expect(log).toEqual('init');
});
});
diff --git a/test/ParserTest.js b/test/ParserTest.js
index 09c3b8de..53ca9eda 100644
--- a/test/ParserTest.js
+++ b/test/ParserTest.js
@@ -41,7 +41,7 @@ LexerTest.prototype.testTokenizeAString = function(){
i++;
assertEquals(tokens[i].index, 15);
- assertEquals(tokens[i].text, "a'c");
+ assertEquals(tokens[i].string, "a'c");
i++;
assertEquals(tokens[i].index, 21);
@@ -49,7 +49,7 @@ LexerTest.prototype.testTokenizeAString = function(){
i++;
assertEquals(tokens[i].index, 22);
- assertEquals(tokens[i].text, 'd"e');
+ assertEquals(tokens[i].string, 'd"e');
};
@@ -68,10 +68,10 @@ LexerTest.prototype.testQuotedString = function(){
var tokens = lexer.parse();
assertEquals(1, tokens[1].index);
- assertEquals("'", tokens[1].text);
+ assertEquals("'", tokens[1].string);
assertEquals(7, tokens[3].index);
- assertEquals('"', tokens[3].text);
+ assertEquals('"', tokens[3].string);
};
@@ -80,14 +80,14 @@ LexerTest.prototype.testQuotedStringEscape = function(){
var lexer = new Lexer(str);
var tokens = lexer.parse();
- assertEquals('"\n\f\r\t\v\u00A0', tokens[0].text);
+ assertEquals('"\n\f\r\t\v\u00A0', tokens[0].string);
};
LexerTest.prototype.testTokenizeUnicode = function(){
var lexer = new Lexer('"\\u00A0"');
var tokens = lexer.parse();
assertEquals(1, tokens.length);
- assertEquals('\u00a0', tokens[0].text);
+ assertEquals('\u00a0', tokens[0].string);
};
LexerTest.prototype.testTokenizeRegExpWithOptions = function(){
@@ -408,7 +408,7 @@ ParserTest.prototype.testItShouldParseOnChangeIntoHashSet = function () {
ParserTest.prototype.testItShouldParseOnChangeBlockIntoHashSet = function () {
var scope = new Scope({count:0});
var listeners = {a:[], b:[]};
- scope.watch("a:{count=count+1;count=count+20;};b:count=count+300",
+ scope.watch("a:{count=count+1;count=count+20;};b:count=count+300",
function(n, fn){listeners[n].push(fn);});
assertEquals(1, scope.watchListeners.a.listeners.length);
@@ -477,3 +477,8 @@ ParserTest.prototype.testNegationBug = function () {
assertEquals(12/6/2, scope.eval("12/6/2"));
};
+ParserTest.prototype.testBugStringConfusesParser = function() {
+ var scope = new Scope();
+ assertEquals('!', scope.eval('suffix = "!"'));
+};
+
diff --git a/test/directivesSpec.js b/test/directivesSpec.js
new file mode 100644
index 00000000..176f9e70
--- /dev/null
+++ b/test/directivesSpec.js
@@ -0,0 +1,71 @@
+describe("directives", function(){
+
+ var compile, element;
+
+ beforeEach(function() {
+ var compiler = new Compiler(angularMarkup, angularDirective, angularWidget);
+ compile = function(html) {
+ element = jqLite(html);
+ var view = compiler.compile(element.element)(element.element);
+ view.init();
+ return view.scope;
+ };
+ });
+
+ it("should ng-init", function() {
+ var scope = compile('<div ng-init="a=123"></div>');
+ expect(scope.get('a')).toEqual(123);
+ });
+
+ it("should ng-eval", function() {
+ var scope = compile('<div ng-init="a=0" ng-eval="a = a + 1"></div>');
+ expect(scope.get('a')).toEqual(0);
+ scope.updateView();
+ expect(scope.get('a')).toEqual(1);
+ scope.updateView();
+ expect(scope.get('a')).toEqual(2);
+ });
+
+ it('should ng-bind', function() {
+ var scope = compile('<div ng-bind="a"></div>');
+ expect(element.text()).toEqual('');
+ scope.set('a', 'misko');
+ scope.updateView();
+ expect(element.text()).toEqual('misko');
+ });
+
+ it('should ng-bind-attr', function(){
+ var scope = compile('<img ng-bind-attr="{src:\'mysrc\', alt:\'myalt\'}"/>');
+ expect(element.attr('src')).toEqual(null);
+ expect(element.attr('alt')).toEqual(null);
+ scope.updateView();
+ expect(element.attr('src')).toEqual('mysrc');
+ expect(element.attr('alt')).toEqual('myalt');
+ });
+
+ it('should ng-non-bindable', function(){
+ var scope = compile('<div ng-non-bindable><span ng-bind="name"></span></div>');
+ scope.set('name', 'misko');
+ scope.updateView();
+ expect(element.text()).toEqual('');
+ });
+
+ it('should ng-repeat over array', function(){
+ var scope = compile('<ul><li ng-repeat="item in items" ng-init="suffix = \';\'" ng-bind="item + suffix"></li></ul>');
+
+ scope.set('items', ['misko', 'shyam']);
+ scope.updateView();
+ expect(element.text()).toEqual('misko;shyam;');
+
+ scope.set('items', ['adam', 'kai', 'brad']);
+ scope.updateView();
+ expect(element.text()).toEqual('adam;kai;brad;');
+
+ scope.set('items', ['brad']);
+ scope.updateView();
+ expect(element.text()).toEqual('brad;');
+ });
+
+ it('should ng-repeat over object', function(){});
+ it('should error on wrong parsing of ng-repeat', function(){});
+});