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: load:
- lib/jasmine/jasmine-0.10.3.js - lib/jasmine/jasmine-0.10.3.js
- lib/jasmine-jstd-adapter/JasmineAdapter.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/Angular.js
- src/*.js - src/*.js
- src/scenario/_namespace.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"> <!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"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> <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="../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> </head>
<body ng:init="$window.$scope = this"> <body ng:init="$window.$scope = this">
<table> <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 uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; } function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
function isElement(node) { 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) { if (msie) {

View file

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

View file

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

View file

@ -238,10 +238,6 @@ if (msie) {
}, },
trigger: function(type) { 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); this[0].fireEvent('on' + type);
} }
}); });

View file

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

View file

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

View file

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

View file

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