Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added tests & updated jQuery

  • Loading branch information...
commit 6c00d40cbf58a8ab046549732bbcd4901bb9a869 1 parent 1cb884d
Craig Spaeth authored
Showing with 34 additions and 156 deletions.
  1. +4 −154 public/jquery.js
  2. +30 −2 public/tests/test.offline.js
View
158 public/jquery.js
4 additions, 154 deletions not shown
View
32 public/tests/test.offline.js
@@ -19,8 +19,8 @@ var baseTest = function( next, data, obj ) {
expectCached = obj.cached;
var successCount = expectCached ? (count + 1) : count;
-
- $.retrieveJSON("/ajax/app", data, function( json, text, flag ) {
+
+ var returned = $.retrieveJSON("/ajax/app", data, function( json, text, flag ) {
if(text == "success") {
if(obj.successFlag) {
ok( flag && flag.cachedAt, "a follow-up request should have the cache time" );
@@ -52,6 +52,12 @@ var baseTest = function( next, data, obj ) {
return obj.returnValue;
}
});
+ if(obj.returnsJQXHR) {
+ ok( returned.readyState > 0, 'retrieveJSON should return jqXHR' );
+ }
+ if(obj.returnsPromise) {
+ ok( returned.fail && returned.done, 'retrieveJSON should return a jQuery promise' );
+ }
}
if( $.support.localStorage ) {
@@ -63,6 +69,14 @@ if( $.support.localStorage ) {
});
});
+ asyncTest("the first time, it returns a jqXHR object from the AJAX call", function() {
+ $(document).dequeue().queue(function(next) {
+ setup(next);
+ }).queue(function(next) {
+ baseTest(next, {}, { start: true, cached: false, returnsJQXHR: true });
+ });
+ });
+
asyncTest("the second time, it gets additional data in the callback", function() {
$(document).dequeue().queue(function(next) {
setup(next);
@@ -96,6 +110,20 @@ if( $.support.localStorage ) {
baseTest(next, {}, { start: true, cached: true, returnValue: false });
});
});
+
+ asyncTest("if you return false, it will return a jQuery.Defered().promise object", function() {
+ // Use an expectation assertion here to confirm that the Ajax request
+ // doesn't run. If it did, we would have two more assertions.
+ expect(3);
+
+ $(document).dequeue().queue(function(next) {
+ setup(next);
+ }).queue(function(next) {
+ baseTest(next, {}, { cached: false });
+ }).queue(function(next) {
+ baseTest(next, {}, { start: true, cached: true, returnValue: false, returnsPromise: true });
+ });
+ });
asyncTest("different data gets cached differently", function() {
$(document).dequeue().queue(function(next) {
Please sign in to comment.
Something went wrong with that request. Please try again.