tests work under jquery and without

This commit is contained in:
Misko Hevery 2010-04-22 17:11:56 -07:00
parent 2a9669e1d8
commit fe434307d1
11 changed files with 36 additions and 30 deletions

View file

@ -3,7 +3,7 @@ server: http://localhost:9876
load:
- lib/jasmine/jasmine-0.10.3.js
- lib/jasmine-jstd-adapter/JasmineAdapter.js
- lib/jquery/jquery-1.4.2.js
# - lib/jquery/jquery-1.4.2.js
- src/Angular.js
- src/*.js
- src/scenario/_namespace.js

View file

@ -1,9 +1,9 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"/><!--
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="../lib/jquery/jquery-1.4.2.js"></script>
--><script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
<script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
</head>
<body ng:init="$window.$scope = this">
<table>

View file

@ -112,7 +112,11 @@ function lowercase(value){ return isString(value) ? value.toLowerCase() : value;
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
function isElement(node) {
return node && (node.nodeName || node instanceof JQLite || node instanceof jQuery);
return node && (node.nodeName || node instanceof JQLite || (jQuery && node instanceof jQuery));
}
function HTML(html) {
this.html = html;
}
if (msie) {

View file

@ -30,8 +30,8 @@ angularDirective("ng-bind", function(expression){
value = this.$tryEval(expression, function(e){
error = toJson(e);
}),
isElem = isElement(value);
if (!isElem && isObject(value)) {
isHtml = value instanceof HTML;
if (!isHtml && isObject(value)) {
value = toJson(value);
}
if (value != lastValue || error != lastError) {
@ -39,9 +39,8 @@ angularDirective("ng-bind", function(expression){
lastError = error;
elementError(element, NG_EXCEPTION, error);
if (error) value = error;
if (isElem) {
element.html('');
element.append(value);
if (isHtml) {
element.html(value.html);
} else {
element.text(value);
}

View file

@ -269,9 +269,7 @@ foreach({
},
'html': function(html){
var div = jqLite('div');
div.html(html);
return div.children();
return new HTML(html);
},
'linky': function(text){
@ -293,7 +291,7 @@ foreach({
raw = raw.substring(i + url.length);
}
html.push(escapeHtml(raw));
return jqLite(html.join(''));
return new HTML(html.join(''));
}
}, function(v,k){angularFilter[k] = v;});

View file

@ -238,10 +238,6 @@ if (msie) {
},
trigger: function(type) {
if (nodeName(this) == 'INPUT' && (lowercase(this.attr('type')) == 'radio' || lowercase(this.attr('type')) == 'checkbox')) {
this[0].checked = ! this[0].checked;
}
this[0].fireEvent('on' + type);
}
});

View file

@ -32,7 +32,7 @@ function valueAccessor(scope, element) {
value = element.val();
force = true;
}
if (element[0].disabled || isString(element.attr('readonly'))) {
if (element[0].disabled || element[0].readOnly) {
elementError(element, NG_VALIDATION_ERROR, null);
invalidWidgets.markValid(element);
return value;

View file

@ -588,13 +588,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() {
var female = jqLite(c.node[0].childNodes[0]);
var male = jqLite(c.node[0].childNodes[1]);
female.trigger('click');
click(female);
assertEquals("female", c.scope.sex);
assertEquals(true, female[0].checked);
assertEquals(false, male[0].checked);
assertEquals("female", female.val());
male.trigger('click');
click(male);
assertEquals("male", c.scope.sex);
assertEquals(false, female[0].checked);
assertEquals(true, male[0].checked);

View file

@ -133,9 +133,9 @@ FiltersTest.prototype.testGoogleChartApiEncode = function() {
};
FiltersTest.prototype.testHtml = function() {
var div = jqLite('<div></div>');
div.append(angular.filter.html("a<b>c</b>d"));
assertEquals("a<b>c</b>d", lowercase(div.html()));
var html = angular.filter.html("a<b>c</b>d");
expect(html instanceof HTML).toBeTruthy();
expect(html.html).toEqual("a<b>c</b>d");
};
FiltersTest.prototype.testLinky = function() {
@ -145,7 +145,7 @@ FiltersTest.prototype.testLinky = function() {
'(<a href="http://a/">http://a/</a>) ' +
'&lt;<a href="http://a/">http://a/</a>&gt; ' +
'<a href="http://1.2/v:~-123">http://1.2/v:~-123</a>. c',
sortedHtml(linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c")));
linky("http://ab/ (http://a/) <http://a/> http://1.2/v:~-123. c").html);
assertEquals(undefined, linky(undefined));
};

View file

@ -148,3 +148,12 @@ function assertThrows(error, fn){
log = noop;
error = noop;
function click(element) {
element = jqLite(element);
if ( (msie || jqLite == window.jQuery) &&
nodeName(element) == 'INPUT' && (lowercase(element.attr('type')) == 'radio' || lowercase(element.attr('type')) == 'checkbox')) {
element[0].checked = ! element[0].checked;
}
element.trigger('click');
}

View file

@ -137,23 +137,23 @@ describe("widget", function(){
it('should call ng-change on button click', function(){
compile('<input type="button" value="Click Me" ng-change="clicked = true"/>');
element.trigger('click');
click(element);
expect(scope.$get('clicked')).toEqual(true);
});
it('should support button alias', function(){
compile('<button ng-change="clicked = true">Click Me</button>');
element.trigger('click');
click(element);
expect(scope.$get('clicked')).toEqual(true);
});
it('should support type="checkbox"', function(){
compile('<input type="checkBox" name="checkbox" checked ng-change="action = true"/>');
expect(scope.checkbox).toEqual(true);
element.trigger('click');
click(element);
expect(scope.checkbox).toEqual(false);
expect(scope.action).toEqual(true);
element.trigger('click');
click(element);
expect(scope.checkbox).toEqual(true);
});
@ -177,7 +177,7 @@ describe("widget", function(){
expect(b.checked).toEqual(true);
expect(scope.clicked).not.toBeDefined();
jqLite(a).trigger('click');
click(a);
expect(scope.chose).toEqual('A');
expect(scope.clicked).toEqual(1);
});
@ -219,7 +219,7 @@ describe("widget", function(){
it('should report error on ng-change exception', function(){
compile('<button ng-change="a-2=x">click</button>');
element.trigger('click');
click(element);
expect(element.hasClass('ng-exception')).toBeTruthy();
});
});