Commits

masklinn committed a10bd78

Error out if adding a new promise on a resolved queue

Comments (0)

Files changed (2)

src/jquery.deferred-queue.js

 
             var promise = $.extend(queueDeferred.promise(), {
                 push: function () {
+                    if (this.isResolved() || this.isRejected()) {
+                        throw new Error("Can not add promises to a resolved "
+                                        + "or rejected promise queue");
+                    }
+
                     promises += 1;
                     $.when.apply(null, arguments).then(
                         resolve, $.proxy(queueDeferred, 'reject'));
             start();
         });
     });
+
+    asyncTest("Adding objects to a resolved queue is an error", 2, function () {
+        var d = $.Deferred();
+        queue.push(d.promise()).then(function () { resolved = true; });
+        d.resolve();
+        setTimeout(function () {
+            ok(resolved);
+            raises(function () {
+                queue.push($.Deferred().promise())
+            });
+            start();
+        });
+    });
 });