mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
smarter normalization of value on option, and htmlParser fixes
This commit is contained in:
@@ -46,10 +46,18 @@ describe("markups", function(){
|
||||
this.addMatchers({
|
||||
toHaveValue: function(expected){
|
||||
this.message = function(){
|
||||
return 'Expected "' + sortedHtml(this.actual) + '" to have value="' + expected + '".';
|
||||
return 'Expected "' + this.actual.html() + '" to have value="' + expected + '".';
|
||||
};
|
||||
|
||||
return this.actual.html().indexOf('value="' + expected + '"') != -1;
|
||||
var value;
|
||||
htmlParser(this.actual.html(), {
|
||||
start:function(tag, attrs){
|
||||
value = attrs.value;
|
||||
},
|
||||
end:noop,
|
||||
chars:noop
|
||||
});
|
||||
return trim(value) == trim(expected);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -70,6 +78,8 @@ describe("markups", function(){
|
||||
});
|
||||
|
||||
it('should set value even if self closing HTML', function(){
|
||||
// IE removes the \n from option, which makes this test pointless
|
||||
if (msie) return;
|
||||
compile('<select name="x"><option>\n</option></select>');
|
||||
expect(element).toHaveValue('\n');
|
||||
});
|
||||
|
||||
@@ -14,6 +14,11 @@ describe('HTML', function(){
|
||||
attrs: attrs,
|
||||
unary: unary
|
||||
};
|
||||
// Since different browsers handle newlines differenttly we trim
|
||||
// so that it is easier to write tests.
|
||||
forEach(attrs, function(value, key){
|
||||
attrs[key] = trim(value);
|
||||
});
|
||||
},
|
||||
chars: function(text_){
|
||||
text = text_;
|
||||
@@ -38,16 +43,22 @@ describe('HTML', function(){
|
||||
|
||||
it('should parse newlines in attributes', function(){
|
||||
htmlParser('<tag attr="\nvalue\n">text</tag>', handler);
|
||||
expect(start).toEqual({tag:'tag', attrs:{attr:'\nvalue\n'}, unary:false});
|
||||
expect(start).toEqual({tag:'tag', attrs:{attr:'value'}, unary:false});
|
||||
expect(text).toEqual('text');
|
||||
});
|
||||
|
||||
it('should parse namespace', function(){
|
||||
htmlParser('<ns:t-a-g ns:a-t-t-r="\nvalue\n">text</ns:t-a-g>', handler);
|
||||
expect(start).toEqual({tag:'ns:t-a-g', attrs:{'ns:a-t-t-r':'\nvalue\n'}, unary:false});
|
||||
expect(start).toEqual({tag:'ns:t-a-g', attrs:{'ns:a-t-t-r':'value'}, unary:false});
|
||||
expect(text).toEqual('text');
|
||||
});
|
||||
|
||||
it('should parse empty value attribute of node', function(){
|
||||
htmlParser('<OPTION selected value="">abc</OPTION>', handler);
|
||||
expect(start).toEqual({tag:'option', attrs:{selected:'', value:''}, unary:false});
|
||||
expect(text).toEqual('abc');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should echo html', function(){
|
||||
|
||||
@@ -70,7 +70,7 @@ beforeEach(function(){
|
||||
expected = toJson(this.actual);
|
||||
}
|
||||
return "Expected " + expected + " to be an Error with message " + toJson(message);
|
||||
}
|
||||
};
|
||||
return this.actual.name == 'Error' && this.actual.message == message;
|
||||
},
|
||||
|
||||
@@ -83,7 +83,7 @@ beforeEach(function(){
|
||||
expected = toJson(this.actual);
|
||||
}
|
||||
return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp);
|
||||
}
|
||||
};
|
||||
return this.actual.name == 'Error' && messageRegexp.test(this.actual.message);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -475,7 +475,7 @@ describe("widget", function(){
|
||||
scope.$eval();
|
||||
|
||||
expect(scope.$element.text()).toBe('foobarC');
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user