tests failing jstd to show cory

This commit is contained in:
Misko Hevery 2010-04-08 13:43:40 -07:00
parent e0ad7dfcd4
commit c4ef1f2fdd
20 changed files with 171 additions and 269 deletions

11
jstd.log Normal file
View file

@ -0,0 +1,11 @@
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null
java.lang.IllegalArgumentException: /com/google/jstestdriver/javascript/mysrc: resource is null

Binary file not shown.

View file

@ -1 +1 @@
java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 java -jar lib/jstestdriver/JsTestDriver.jar --port 9876 --runnerMode DEBUG

View file

@ -83,7 +83,7 @@ function extensionMap(angular, name) {
} }
function jqLiteWrap(element) { function jqLiteWrap(element) {
if (typeof element == 'string') { if (isString(element)) {
var div = document.createElement('div'); var div = document.createElement('div');
div.innerHTML = element; div.innerHTML = element;
element = div.childNodes[0]; element = div.childNodes[0];
@ -102,6 +102,12 @@ 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 nodeName(element) { return (element[0] || element).nodeName; } function nodeName(element) { return (element[0] || element).nodeName; }
function isVisible(element) {
var rect = element[0].getBoundingClientRect();
return rect.width !=0 && rect.height !=0;
}
function map(obj, iterator, context) { function map(obj, iterator, context) {
var results = []; var results = [];
foreach(obj, function(value, index, list) { foreach(obj, function(value, index, list) {

View file

@ -24,7 +24,7 @@ var angularFilterGoogleChartApi;
foreach({ foreach({
'currency': function(amount){ 'currency': function(amount){
jQuery(this.$element).toggleClass('ng-format-negative', amount < 0); this.$element.toggleClass('ng-format-negative', amount < 0);
return '$' + angularFilter['number'].apply(this, [amount, 2]); return '$' + angularFilter['number'].apply(this, [amount, 2]);
}, },
@ -60,7 +60,7 @@ foreach({
}, },
'json': function(object) { 'json': function(object) {
jQuery(this.$element).addClass("ng-monospace"); this.$element.addClass("ng-monospace");
return toJson(object, true); return toJson(object, true);
}, },

View file

@ -140,6 +140,11 @@ JQLite.prototype = {
this[0].className = trim((" " + this[0].className + " ").replace(/[\n\t]/g, " ").replace(" " + selector + " ", "")); this[0].className = trim((" " + this[0].className + " ").replace(/[\n\t]/g, " ").replace(" " + selector + " ", ""));
}, },
toggleClass: function(selector, condition) {
var self = this;
(condition ? self.addClass : self.removeClass).call(self, selector);
},
addClass: function( selector ) { addClass: function( selector ) {
if (!this.hasClass(selector)) { if (!this.hasClass(selector)) {
this[0].className = trim(this[0].className + ' ' + selector); this[0].className = trim(this[0].className + ' ' + selector);

View file

@ -22,16 +22,20 @@ function valueAccessor(scope, element) {
var validatorName = element.attr('ng-validate') || NOOP, var validatorName = element.attr('ng-validate') || NOOP,
validator = compileValidator(validatorName), validator = compileValidator(validatorName),
required = element.attr('ng-required'), required = element.attr('ng-required'),
lastError, lastError, lastVisible,
invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop}; invalidWidgets = scope.$invalidWidgets || {markValid:noop, markInvalid:noop};
required = required || required === ''; required = required || required === '';
if (!validator) throw "Validator named '" + validatorName + "' not found."; if (!validator) throw "Validator named '" + validatorName + "' not found.";
function validate(value) { function validate(value) {
var error = required && !trim(value) ? "Required" : validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value); var error = required && !trim(value) ?
if (error !== lastError) { "Required" :
validator({state:scope, scope:{get:scope.$get, set:scope.$set}}, value),
visible = isVisible(element);
if (error !== lastError || visible !== lastVisible) {
elementError(element, NG_VALIDATION_ERROR, error); elementError(element, NG_VALIDATION_ERROR, error);
lastError = error; lastError = error;
if (error) lastVisible = visible;
if (error && visible)
invalidWidgets.markInvalid(element); invalidWidgets.markInvalid(element);
else else
invalidWidgets.markValid(element); invalidWidgets.markValid(element);

View file

@ -174,34 +174,6 @@ BinderTest.prototype.testButtonElementActionExecutesInScope = function(){
assertTrue(savedCalled); assertTrue(savedCalled);
}; };
BinderTest.prototype.XtestParseEmptyAnchor = function(){
var binder = this.compile("<div/>").binder;
var location = binder.location;
var anchor = binder.anchor;
location.url = "a#x=1";
binder.parseAnchor();
assertEquals(1, binder.anchor.x);
location.url = "a#";
binder.parseAnchor();
assertTrue("old values did not get removed", !binder.anchor.x);
assertTrue("anchor gor replaced", anchor === binder.anchor);
assertEquals('undefined', typeof (anchor[""]));
};
BinderTest.prototype.XtestParseAnchor = function(){
var binder = this.compile("<div/>").binder;
var location = binder.location;
location.url = "a#x=1";
binder.parseAnchor();
assertEquals(binder.anchor.x, "1");
location.url = "a#a=b&c=%20&d";
binder.parseAnchor();
assertEquals(binder.anchor.a, 'b');
assertEquals(binder.anchor.c, ' ');
assertTrue(binder.anchor.d !== null);
assertTrue(!binder.anchor.x);
};
BinderTest.prototype.testRepeaterUpdateBindings = function(){ BinderTest.prototype.testRepeaterUpdateBindings = function(){
var a = this.compile('<ul><LI ng-repeat="item in model.items" ng-bind="item.a"/></ul>'); var a = this.compile('<ul><LI ng-repeat="item in model.items" ng-bind="item.a"/></ul>');
var form = a.node; var form = a.node;
@ -355,18 +327,6 @@ BinderTest.prototype.testNestedRepeater = function() {
'</div></div>', sortedHtml(a.node)); '</div></div>', sortedHtml(a.node));
}; };
BinderTest.prototype.XtestRadioButtonGetsPrefixed = function () {
var a = this.compile('<div><input ng-repeat="m in model" type="radio" name="m.a" value="on"/></div>');
a.scope.$set('model', ['a1', 'a2']);
a.scope.$eval();
assertEquals('</div>' +
'<#comment></#comment>'+
'<input name="0:m.a" ng-repeat-index="0" type="radio" value="on"></input>'+
'<input name="1:m.a" ng-repeat-index="1" type="radio" value="on"></input></div>',
sortedHtml(a.node));
};
BinderTest.prototype.testHideBindingExpression = function() { BinderTest.prototype.testHideBindingExpression = function() {
var a = this.compile('<div ng-hide="hidden == 3"/>'); var a = this.compile('<div ng-hide="hidden == 3"/>');
@ -525,31 +485,6 @@ BinderTest.prototype.testShouldTemplateBindPreElements = function () {
assertEquals('<pre ng-bind-template="Hello {{name}}!">Hello World!</pre>', sortedHtml(c.node)); assertEquals('<pre ng-bind-template="Hello {{name}}!">Hello World!</pre>', sortedHtml(c.node));
}; };
BinderTest.prototype.XtestDissableAutoSubmit = function() {
var c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:true});
assertEquals(
'<input ng-action="$save()" ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}" type="submit" value="S"></input>',
sortedHtml(c.node));
c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:false});
assertEquals(
'<input type="submit" value="S"></input>',
sortedHtml(c.node));
};
BinderTest.prototype.XtestSettingAnchorToNullOrUndefinedRemovesTheAnchorFromURL = function() {
var c = this.compile('');
c.binder.location.set("http://server/#a=1&b=2");
c.binder.parseAnchor();
assertEquals('1', c.binder.anchor.a);
assertEquals('2', c.binder.anchor.b);
c.binder.anchor.a = null;
c.binder.anchor.b = null;
c.binder.updateAnchor();
assertEquals('http://server/#', c.binder.location.get());
};
BinderTest.prototype.testFillInOptionValueWhenMissing = function() { BinderTest.prototype.testFillInOptionValueWhenMissing = function() {
var c = this.compile( var c = this.compile(
'<select><option selected="true">{{a}}</option><option value="">{{b}}</option><option>C</option></select>'); '<select><option selected="true">{{a}}</option><option value="">{{b}}</option><option>C</option></select>');
@ -570,9 +505,11 @@ BinderTest.prototype.testFillInOptionValueWhenMissing = function() {
expect(optionC.text()).toEqual('C'); expect(optionC.text()).toEqual('C');
}; };
BinderTest.prototype.XtestValidateForm = function() { BinderTest.prototype.testValidateForm = function() {
var c = this.compile('<input name="name" ng-required>' + var doc = jqLite(document.body);
'<div ng-repeat="item in items"><input name="item.name" ng-required/></div>'); doc.append('<div><input name="name" ng-required>' +
'<div ng-repeat="item in items"><input name="item.name" ng-required/></div></div>');
var c = this.compile(doc);
var items = [{}, {}]; var items = [{}, {}];
c.scope.$set("items", items); c.scope.$set("items", items);
c.scope.$eval(); c.scope.$eval();
@ -599,8 +536,9 @@ BinderTest.prototype.XtestValidateForm = function() {
assertEquals(0, c.scope.$get("$invalidWidgets.length")); assertEquals(0, c.scope.$get("$invalidWidgets.length"));
}; };
BinderTest.prototype.XtestValidateOnlyVisibleItems = function(){ BinderTest.prototype.testValidateOnlyVisibleItems = function(){
var c = this.compile('<input name="name" ng-required><input ng-show="show" name="name" ng-required>'); var c = this.compile('<div><input name="name" ng-required><input ng-show="show" name="name" ng-required></div>');
jqLite(document.body).append(c.node);
c.scope.$set("show", true); c.scope.$set("show", true);
c.scope.$eval(); c.scope.$eval();
assertEquals(2, c.scope.$get("$invalidWidgets.length")); assertEquals(2, c.scope.$get("$invalidWidgets.length"));
@ -629,62 +567,6 @@ BinderTest.prototype.testDeleteAttributeIfEvaluatesFalse = function() {
assertChild(5, false); assertChild(5, false);
}; };
BinderTest.prototype.XtestItShouldCallListenersWhenAnchorChanges = function() {
var log = "";
var c = this.compile('<div ng-watch="$anchor.counter:count = count+1">');
c.scope.$set("count", 0);
c.scope.$watch("$anchor.counter", function(newValue, oldValue){
log += oldValue + "->" + newValue + ";";
});
assertEquals(0, c.scope.$get("count"));
c.binder.location.url = "#counter=1";
c.binder.onUrlChange();
assertEquals(1, c.scope.$get("count"));
c.binder.location.url = "#counter=1";
c.binder.onUrlChange();
assertEquals(1, c.scope.$get("count"));
c.binder.location.url = "#counter=2";
c.binder.onUrlChange();
assertEquals(2, c.scope.$get("count"));
c.binder.location.url = "#counter=2";
c.binder.onUrlChange();
assertEquals(2, c.scope.$get("count"));
c.binder.location.url = "#";
c.binder.onUrlChange();
assertEquals("undefined->1;1->2;2->undefined;", log);
assertEquals(3, c.scope.$get("count"));
};
BinderTest.prototype.XtestParseQueryString = function(){
var binder = new Binder();
assertJsonEquals({"a":"1"}, binder.parseQueryString("a=1"));
assertJsonEquals({"a":"1", "b":"two"}, binder.parseQueryString("a=1&b=two"));
assertJsonEquals({}, binder.parseQueryString(""));
assertJsonEquals({"a":"1", "b":""}, binder.parseQueryString("a=1&b="));
assertJsonEquals({"a":"1", "b":""}, binder.parseQueryString("a=1&b"));
assertJsonEquals({"a":"1", "b":" 2 "}, binder.parseQueryString("a=1&b=%202%20"));
assertJsonEquals({"a a":"1", "b":"2"}, binder.parseQueryString("a%20a=1&b=2"));
};
BinderTest.prototype.XtestSetBinderAnchorTriggersListeners = function(){
expectAsserts(2);
var doc = this.compile("<div/>");
doc.scope.$watch("$anchor.name", function(newVal, oldVal) {
assertEquals("new", newVal);
assertEquals(undefined, oldVal);
});
doc.$anchor.name = "new";
doc.binder.onUrlChange("http://base#name=new");
};
BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){ BinderTest.prototype.testItShouldDisplayErrorWhenActionIsSyntacticlyIncorect = function(){
var c = this.compile('<div>' + var c = this.compile('<div>' +
'<input type="button" ng-click="greeting=\'ABC\'"/>' + '<input type="button" ng-click="greeting=\'ABC\'"/>' +
@ -768,9 +650,9 @@ BinderTest.prototype.testItBindHiddenInputFields = function(){
assertEquals("abc", x.scope.$get("myName")); assertEquals("abc", x.scope.$get("myName"));
}; };
BinderTest.prototype.xtestItShouldRenderMultiRootHtmlInBinding = function() { BinderTest.prototype.XtestItShouldRenderMultiRootHtmlInBinding = function() {
var x = this.compile('<div>before {{a|html}}after</div>'); var x = this.compile('<div>before {{a|html}}after</div>');
x.scope.$set("a", "a<b>c</b>d"); x.scope.a = "a<b>c</b>d";
x.scope.$eval(); x.scope.$eval();
assertEquals( assertEquals(
'<div>before <span ng-bind="a|html">a<b>c</b>d</span>after</div>', '<div>before <span ng-bind="a|html">a<b>c</b>d</span>after</div>',
@ -790,20 +672,3 @@ BinderTest.prototype.testItShouldUseFormaterForText = function() {
assertEquals('1, 2, 3', input[0].value); assertEquals('1, 2, 3', input[0].value);
}; };
BinderTest.prototype.XtestWriteAnchor = function(){
var binder = this.compile("<div/>").binder;
binder.location.set('a');
binder.anchor.a = 'b';
binder.anchor.c = ' ';
binder.anchor.d = true;
binder.updateAnchor();
assertEquals(binder.location.get(), "a#a=b&c=%20&d");
};
BinderTest.prototype.XtestWriteAnchorAsPartOfTheUpdateView = function(){
var binder = this.compile("<div/>").binder;
binder.location.set('a');
binder.anchor.a = 'b';
binder.updateView();
assertEquals(binder.location.get(), "a#a=b");
};

View file

@ -7,6 +7,6 @@ ConsoleTest.prototype.XtestConsoleWrite = function(){
assertEquals(jqLite(consoleNode).text(), 'Hello world'); assertEquals(jqLite(consoleNode).text(), 'Hello world');
assertEquals(jqLite(consoleNode.childNodes[0])[0].className, 'error'); assertEquals(jqLite(consoleNode.childNodes[0])[0].className, 'error');
consoleLog("error",["Bye"]); consoleLog("error",["Bye"]);
assertEquals($(consoleNode).text(), 'Hello worldBye'); assertEquals(jqLite(consoleNode).text(), 'Hello worldBye');
consoleNode = null; consoleNode = null;
}; };

View file

@ -1,8 +1,8 @@
FiltersTest = TestCase('FiltersTest'); FiltersTest = TestCase('FiltersTest');
FiltersTest.prototype.XtestCurrency = function(){ FiltersTest.prototype.testCurrency = function(){
var html = $('<span/>'); var html = jqLite('<span/>');
var context = {$element:html[0]}; var context = {$element:html};
var currency = bind(context, angular.filter.currency); var currency = bind(context, angular.filter.currency);
assertEquals(currency(0), '$0.00'); assertEquals(currency(0), '$0.00');
@ -24,8 +24,8 @@ FiltersTest.prototype.testFilterThisIsContext = function(){
delete angular.filter['testFn']; delete angular.filter['testFn'];
}; };
FiltersTest.prototype.XtestNumberFormat = function(){ FiltersTest.prototype.testNumberFormat = function(){
var context = {jqElement:$('<span/>')}; var context = {jqElement:jqLite('<span/>')};
var number = bind(context, angular.filter.number); var number = bind(context, angular.filter.number);
assertEquals('0', number(0, 0)); assertEquals('0', number(0, 0));
@ -37,11 +37,11 @@ FiltersTest.prototype.XtestNumberFormat = function(){
assertEquals("", number(1/0)); assertEquals("", number(1/0));
}; };
FiltersTest.prototype.XtestJson = function () { FiltersTest.prototype.testJson = function () {
assertEquals(toJson({a:"b"}, true), angular.filter.json({a:"b"})); assertEquals(toJson({a:"b"}, true), angular.filter.json.call({$element:jqLite('<div></div>')}, {a:"b"}));
}; };
FiltersTest.prototype.XtestPackageTracking = function () { FiltersTest.prototype.testPackageTracking = function () {
var assert = function(title, trackingNo) { var assert = function(title, trackingNo) {
var val = angular.filter.trackPackage(trackingNo, title); var val = angular.filter.trackPackage(trackingNo, title);
assertNotNull("Did Not Match: " + trackingNo, val); assertNotNull("Did Not Match: " + trackingNo, val);
@ -69,7 +69,7 @@ FiltersTest.prototype.XtestPackageTracking = function () {
assert('USPS', '9102801438635051633253'); assert('USPS', '9102801438635051633253');
}; };
FiltersTest.prototype.XtestLink = function() { FiltersTest.prototype.testLink = function() {
var assert = function(text, url, obj){ var assert = function(text, url, obj){
var val = angular.filter.link(obj); var val = angular.filter.link(obj);
assertEquals(angular.filter.Meta.TAG, val.TAG); assertEquals(angular.filter.Meta.TAG, val.TAG);
@ -80,14 +80,7 @@ FiltersTest.prototype.XtestLink = function() {
assert("a@b.com", "mailto:a@b.com", "a@b.com"); assert("a@b.com", "mailto:a@b.com", "a@b.com");
}; };
FiltersTest.prototype.XtestBytes = function(){ FiltersTest.prototype.testImage = function(){
var controller = new FileController();
assertEquals(angular.filter.bytes(123), '123 bytes');
assertEquals(angular.filter.bytes(1234), '1.2 KB');
assertEquals(angular.filter.bytes(1234567), '1.1 MB');
};
FiltersTest.prototype.XtestImage = function(){
assertEquals(null, angular.filter.image()); assertEquals(null, angular.filter.image());
assertEquals(null, angular.filter.image({})); assertEquals(null, angular.filter.image({}));
assertEquals(null, angular.filter.image("")); assertEquals(null, angular.filter.image(""));
@ -100,7 +93,7 @@ FiltersTest.prototype.XtestImage = function(){
angular.filter.image({url:"abc"}, 10, 20).html); angular.filter.image({url:"abc"}, 10, 20).html);
}; };
FiltersTest.prototype.XtestQRcode = function() { FiltersTest.prototype.testQRcode = function() {
assertEquals( assertEquals(
'<img width="200" height="200" src="http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr"/>', '<img width="200" height="200" src="http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr"/>',
angular.filter.qrcode('Hello world').html); angular.filter.qrcode('Hello world').html);
@ -109,17 +102,17 @@ FiltersTest.prototype.XtestQRcode = function() {
angular.filter.qrcode('http://server?a&b=c', 100).html); angular.filter.qrcode('http://server?a&b=c', 100).html);
}; };
FiltersTest.prototype.XtestLowercase = function() { FiltersTest.prototype.testLowercase = function() {
assertEquals('abc', angular.filter.lowercase('AbC')); assertEquals('abc', angular.filter.lowercase('AbC'));
assertEquals(null, angular.filter.lowercase(null)); assertEquals(null, angular.filter.lowercase(null));
}; };
FiltersTest.prototype.XtestUppercase = function() { FiltersTest.prototype.testUppercase = function() {
assertEquals('ABC', angular.filter.uppercase('AbC')); assertEquals('ABC', angular.filter.uppercase('AbC'));
assertEquals(null, angular.filter.uppercase(null)); assertEquals(null, angular.filter.uppercase(null));
}; };
FiltersTest.prototype.XtestLineCount = function() { FiltersTest.prototype.testLineCount = function() {
assertEquals(1, angular.filter.linecount(null)); assertEquals(1, angular.filter.linecount(null));
assertEquals(1, angular.filter.linecount('')); assertEquals(1, angular.filter.linecount(''));
assertEquals(1, angular.filter.linecount('a')); assertEquals(1, angular.filter.linecount('a'));
@ -127,30 +120,30 @@ FiltersTest.prototype.XtestLineCount = function() {
assertEquals(3, angular.filter.linecount('a\nb\nc')); assertEquals(3, angular.filter.linecount('a\nb\nc'));
}; };
FiltersTest.prototype.XtestIf = function() { FiltersTest.prototype.testIf = function() {
assertEquals('A', angular.filter['if']('A', true)); assertEquals('A', angular.filter['if']('A', true));
assertEquals(undefined, angular.filter['if']('A', false)); assertEquals(undefined, angular.filter['if']('A', false));
}; };
FiltersTest.prototype.XtestUnless = function() { FiltersTest.prototype.testUnless = function() {
assertEquals('A', angular.filter.unless('A', false)); assertEquals('A', angular.filter.unless('A', false));
assertEquals(undefined, angular.filter.unless('A', true)); assertEquals(undefined, angular.filter.unless('A', true));
}; };
FiltersTest.prototype.XtestGoogleChartApiEncode = function() { FiltersTest.prototype.testGoogleChartApiEncode = function() {
assertEquals( assertEquals(
'<img width="200" height="200" src="http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr"/>', '<img width="200" height="200" src="http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr"/>',
angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).html); angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).html);
}; };
FiltersTest.prototype.XtestHtml = function() { FiltersTest.prototype.testHtml = function() {
assertEquals( assertEquals(
"a<b>c</b>d", "a<b>c</b>d",
angular.filter.html("a<b>c</b>d").html); angular.filter.html("a<b>c</b>d").html);
assertTrue(angular.filter.html("a<b>c</b>d") instanceof angular.filter.Meta); assertTrue(angular.filter.html("a<b>c</b>d") instanceof angular.filter.Meta);
}; };
FiltersTest.prototype.XtestLinky = function() { FiltersTest.prototype.testLinky = function() {
var linky = angular.filter.linky; var linky = angular.filter.linky;
assertEquals( assertEquals(
'<a href="http://ab">http://ab</a> ' + '<a href="http://ab">http://ab</a> ' +

View file

@ -404,36 +404,6 @@ ParserTest.prototype.testMissingThrowsError = function() {
} }
}; };
ParserTest.prototype.XtestItShouldParseOnChangeIntoHashSet = function () {
var scope = createScope({count:0});
scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300");
scope.watchListeners["$anchor.a"].listeners[0]();
assertEquals(1, scope.$get("count"));
scope.watchListeners["$anchor.a"].listeners[1]();
assertEquals(21, scope.$get("count"));
scope.watchListeners["b"].listeners[0]({scope:scope});
assertEquals(321, scope.$get("count"));
};
ParserTest.prototype.XtestItShouldParseOnChangeBlockIntoHashSet = function () {
var scope = createScope({count:0});
var listeners = {a:[], b:[]};
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);
assertEquals(1, scope.watchListeners.b.listeners.length);
scope.watchListeners["a"].listeners[0]();
assertEquals(21, scope.$get("count"));
scope.watchListeners["b"].listeners[0]();
assertEquals(321, scope.$get("count"));
};
ParserTest.prototype.XtestItShouldParseEmptyOnChangeAsNoop = function () {
var scope = createScope();
scope.watch("", function(){fail();});
};
ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () { ParserTest.prototype.testItShouldCreateClosureFunctionWithNoArguments = function () {
var scope = createScope(); var scope = createScope();
var fn = scope.$eval("{:value}"); var fn = scope.$eval("{:value}");
@ -462,16 +432,6 @@ ParserTest.prototype.testItShouldHaveDefaultArugument = function(){
assertEquals(4, fn(2)); assertEquals(4, fn(2));
}; };
ParserTest.prototype.XtestReturnFunctionsAreNotBound = function(){
var scope = createScope();
scope.entity("Group", new DataStore());
var Group = scope.$get("Group");
assertEquals("eval Group", "function", typeof scope.$eval("Group"));
assertEquals("direct Group", "function", typeof Group);
assertEquals("eval Group.all", "function", typeof scope.$eval("Group.query"));
assertEquals("direct Group.all", "function", typeof Group.query);
};
ParserTest.prototype.testDoubleNegationBug = function (){ ParserTest.prototype.testDoubleNegationBug = function (){
var scope = createScope(); var scope = createScope();
assertEquals(true, scope.$eval('true')); assertEquals(true, scope.$eval('true'));

View file

@ -19,46 +19,33 @@ describe("ScenarioSpec: Compilation", function(){
}); });
describe("ScenarioSpec: Scope", function(){ describe("ScenarioSpec: Scope", function(){
xit("should have set, get, eval, $init, updateView methods", function(){ it("should have set, get, eval, $init, updateView methods", function(){
var scope = compile('<div>{{a}}</div>').$init(); var scope = compile('<div>{{a}}</div>').$init();
scope.$eval("$invalidWidgets.push({})"); scope.$eval("$invalidWidgets.push({})");
expect(scope.$set("a", 2)).toEqual(2); expect(scope.$set("a", 2)).toEqual(2);
expect(scope.$get("a")).toEqual(2); expect(scope.$get("a")).toEqual(2);
expect(scope.$eval("a=3")).toEqual(3); expect(scope.$eval("a=3")).toEqual(3);
scope.$eval(); scope.$eval();
expect(scope.$eval("$invalidWidgets")).toEqual([]);
expect(jqLite(scope.$element).text()).toEqual('3'); expect(jqLite(scope.$element).text()).toEqual('3');
}); });
xit("should have $ objects", function(){ it("should have $ objects", function(){
var scope = compile('<div></div>', {a:"b"}); var scope = compile('<div></div>', {$config: {a:"b"}});
expect(scope.$get('$anchor')).toBeDefined(); expect(scope.$get('$location')).toBeDefined();
expect(scope.$get('$eval')).toBeDefined(); expect(scope.$get('$eval')).toBeDefined();
expect(scope.$get('$config')).toBeDefined(); expect(scope.$get('$config')).toBeDefined();
expect(scope.$get('$config.a')).toEqual("b"); expect(scope.$get('$config.a')).toEqual("b");
expect(scope.$get('$datastore')).toBeDefined();
}); });
}); });
xdescribe("ScenarioSpec: configuration", function(){ describe("ScenarioSpec: configuration", function(){
it("should take location object", function(){ it("should take location object", function(){
var url = "http://server/#book=moby"; var url = "http://server/#?book=moby";
var onUrlChange; var scope = compile("<div>{{$location}}</div>");
var location = { var $location = scope.$get('$location');
listen:function(fn){onUrlChange=fn;}, expect($location.hashSearch.book).toBeUndefined();
set:function(u){url = u;}, scope.$browser.setUrl(url);
get:function(){return url;} scope.$browser.fireUrlWatchers();
}; expect($location.hashSearch.book).toEqual('moby');
var scope = compile("<div>{{$anchor}}</div>", {location:location});
var $anchor = scope.$get('$anchor');
expect($anchor.book).toBeUndefined();
expect(onUrlChange).toBeUndefined();
scope.$init();
expect($anchor.book).toEqual('moby');
expect(onUrlChange).toBeDefined();
url = "http://server/#book=none";
onUrlChange();
expect($anchor.book).toEqual('none');
}); });
}); });

View file

@ -1,20 +1,20 @@
ValidatorTest = TestCase('ValidatorTest'); ValidatorTest = TestCase('ValidatorTest');
ValidatorTest.prototype.XtestItShouldHaveThisSet = function() { ValidatorTest.prototype.testItShouldHaveThisSet = function() {
expectAsserts(5); var validator = {};
var self;
angular.validator.myValidator = function(first, last){ angular.validator.myValidator = function(first, last){
assertEquals('misko', first); validator.first = first;
assertEquals('hevery', last); validator.last = last;
self = this; validator._this = this;
}; };
var c = compile('<input name="name" ng-validate="myValidator:\'hevery\'"/>'); var scope = compile('<input name="name" ng-validate="myValidator:\'hevery\'"/>');
c.scope.$set('name', 'misko'); scope.name = 'misko';
c.scope.$set('state', 'abc'); scope.$init();
c.scope.$eval(); assertEquals('misko', validator.first);
assertEquals('abc', self.state); assertEquals('hevery', validator.last);
assertEquals('misko', self.name); assertSame(scope, validator._this);
assertEquals('name', self.$element.name); delete angular.validator.myValidator;
scope.$element.remove();
}; };
ValidatorTest.prototype.testRegexp = function() { ValidatorTest.prototype.testRegexp = function() {

View file

@ -45,6 +45,12 @@ MockBrowser.prototype = {
watchUrl: function(fn) { watchUrl: function(fn) {
this.watches.push(fn); this.watches.push(fn);
},
fireUrlWatchers: function() {
for(var i=0; i<this.watches.length; i++) {
this.watches[i](this.url);
}
} }
}; };

View file

@ -141,20 +141,22 @@ describe("directives", function(){
it('should ng-show', function(){ it('should ng-show', function(){
var scope = compile('<div ng-hide="hide"></div>'); var scope = compile('<div ng-hide="hide"></div>');
jqLite(document.body).append(scope.$element);
scope.$eval(); scope.$eval();
expect(isVisible(element)).toEqual(true); expect(isVisible(scope.$element)).toEqual(true);
scope.$set('hide', true); scope.$set('hide', true);
scope.$eval(); scope.$eval();
expect(isVisible(element)).toEqual(false); expect(isVisible(scope.$element)).toEqual(false);
}); });
it('should ng-hide', function(){ it('should ng-hide', function(){
var scope = compile('<div ng-show="show"></div>'); var scope = compile('<div ng-show="show"></div>');
jqLite(document.body).append(scope.$element);
scope.$eval(); scope.$eval();
expect(isVisible(element)).toEqual(false); expect(isVisible(scope.$element)).toEqual(false);
scope.$set('show', true); scope.$set('show', true);
scope.$eval(); scope.$eval();
expect(isVisible(element)).toEqual(true); expect(isVisible(scope.$element)).toEqual(true);
}); });
it('should ng-controller', function(){ it('should ng-controller', function(){

View file

@ -7,13 +7,13 @@ BinderTest.prototype.testExpandEntityTagWithName = function(){
assertEquals("friend", c.scope.$get("friend.$$anchor")); assertEquals("friend", c.scope.$get("friend.$$anchor"));
}; };
BinderTest.prototype.XtestExpandSubmitButtonToAction = function(){ BinderTest.prototype.testExpandSubmitButtonToAction = function(){
var html = this.compileToHtml('<input type="submit" value="Save">'); var html = this.compileToHtml('<input type="submit" value="Save">');
assertTrue(html, html.indexOf('ng-action="$save()"') > 0 ); assertTrue(html, html.indexOf('ng-action="$save()"') > 0 );
assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 ); assertTrue(html, html.indexOf('ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}"') > 0 );
}; };
BinderTest.prototype.XtestReplaceFileUploadWithSwf = function(){ BinderTest.prototype.testReplaceFileUploadWithSwf = function(){
expectAsserts(1); expectAsserts(1);
var form = jQuery("body").append('<div id="testTag"><input type="file"></div>'); var form = jQuery("body").append('<div id="testTag"><input type="file"></div>');
form.data('scope', new Scope()); form.data('scope', new Scope());

View file

@ -0,0 +1,62 @@
ParserTest.prototype.testReturnFunctionsAreNotBound = function(){
var scope = createScope();
scope.entity("Group", new DataStore());
var Group = scope.$get("Group");
assertEquals("eval Group", "function", typeof scope.$eval("Group"));
assertEquals("direct Group", "function", typeof Group);
assertEquals("eval Group.all", "function", typeof scope.$eval("Group.query"));
assertEquals("direct Group.all", "function", typeof Group.query);
};
ParserTest.prototype.XtestItShouldParseEmptyOnChangeAsNoop = function () {
var scope = createScope();
scope.watch("", function(){fail();});
};
ParserTest.prototype.XtestItShouldParseOnChangeIntoHashSet = function () {
var scope = createScope({count:0});
scope.watch("$anchor.a:count=count+1;$anchor.a:count=count+20;b:count=count+300");
scope.watchListeners["$anchor.a"].listeners[0]();
assertEquals(1, scope.$get("count"));
scope.watchListeners["$anchor.a"].listeners[1]();
assertEquals(21, scope.$get("count"));
scope.watchListeners["b"].listeners[0]({scope:scope});
assertEquals(321, scope.$get("count"));
};
ParserTest.prototype.XtestItShouldParseOnChangeBlockIntoHashSet = function () {
var scope = createScope({count:0});
var listeners = {a:[], b:[]};
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);
assertEquals(1, scope.watchListeners.b.listeners.length);
scope.watchListeners["a"].listeners[0]();
assertEquals(21, scope.$get("count"));
scope.watchListeners["b"].listeners[0]();
assertEquals(321, scope.$get("count"));
};
FiltersTest.prototype.testBytes = function(){
var controller = new FileController();
assertEquals(angular.filter.bytes(123), '123 bytes');
assertEquals(angular.filter.bytes(1234), '1.2 KB');
assertEquals(angular.filter.bytes(1234567), '1.1 MB');
};
BinderTest.prototype.testDissableAutoSubmit = function() {
var c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:true});
assertEquals(
'<input ng-action="$save()" ng-bind-attr="{"disabled":"{{$invalidWidgets}}"}" type="submit" value="S"></input>',
sortedHtml(c.node));
c = this.compile('<input type="submit" value="S"/>', null, {autoSubmit:false});
assertEquals(
'<input type="submit" value="S"></input>',
sortedHtml(c.node));
};

View file

@ -66,7 +66,9 @@ describe("service $invalidWidgets", function(){
}); });
it("should count number of invalid widgets", function(){ it("should count number of invalid widgets", function(){
var scope = compile('<input name="price" ng-required></input>').$init(); var doc = jqLite(window.document.body);
doc.append('<input name="price" ng-required></input>');
var scope = compile(doc).$init();
expect(scope.$invalidWidgets.length).toEqual(1); expect(scope.$invalidWidgets.length).toEqual(1);
scope.price = 123; scope.price = 123;
scope.$eval(); scope.$eval();

View file

@ -74,19 +74,18 @@ function sortedHtml(element) {
return html; return html;
} }
function isVisible(node) { function isCssVisible(node) {
var display = node.css('display'); var display = node.css('display');
if (display == 'block') display = ""; if (display == 'block') display = "";
return display != 'none'; return display != 'none';
} }
function assertHidden(node) { function assertHidden(node) {
var display = node.css('display'); assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isCssVisible(node));
assertFalse("Node should be hidden but vas visible: " + sortedHtml(node), isVisible(node));
} }
function assertVisible(node) { function assertVisible(node) {
assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isVisible(node)); assertTrue("Node should be visible but vas hidden: " + sortedHtml(node), isCssVisible(node));
} }
function assertJsonEquals(expected, actual) { function assertJsonEquals(expected, actual) {