From 469cdff6e8ae5a982ab933d7c4e6745ab0338473 Mon Sep 17 00:00:00 2001 From: Domenic Denicola Date: Sun, 5 May 2013 00:32:39 -0400 Subject: [PATCH] Clean up tests. --- spec/q-spec.js | 102 ++++++++++++++++++++++++------------------------- 1 file changed, 49 insertions(+), 53 deletions(-) diff --git a/spec/q-spec.js b/spec/q-spec.js index 4b31a517..05f3718c 100644 --- a/spec/q-spec.js +++ b/spec/q-spec.js @@ -123,7 +123,7 @@ describe("defer and when", function () { it("resolves multiple observers", function (done) { var nextTurn = false; - var resolution = 'Taram pam param!'; + var resolution = "Taram pam param!"; var deferred = Q.defer(); var count = 10; var i = 0; @@ -544,7 +544,7 @@ describe("promises for objects", function () { it("fulfills a promise", function () { var object = {}; return Q.resolve(object) - .set('a', 1) + .set("a", 1) .then(function (result) { expect(result).toBe(undefined); expect(object.a).toBe(1); @@ -555,7 +555,7 @@ describe("promises for objects", function () { var exception = new Error("Gah!"); return Q.reject(exception) .set("a", 1) - .then(function (result) { + .then(function () { expect("frozen over").toBe("quite warm"); }, function (_exception) { expect(_exception).toBe(exception); @@ -571,11 +571,11 @@ describe("promises for objects", function () { return Q.fcall(function () { return object; }) - .del('a') + .del("a") .then(function (result) { - expect('a' in object).toBe(false); + expect("a" in object).toBe(false); expect(result).toBe(void 0); - }, function (exception) { + }, function () { expect("up").toBe("down"); }); }); @@ -585,7 +585,7 @@ describe("promises for objects", function () { return Q.fcall(function () { throw exception; }) - .del('a') + .del("a") .then(function () { expect(true).toBe(false); }, function (_exception) { @@ -604,7 +604,7 @@ describe("promises for objects", function () { return 1 + value; } }; - return Q.when(Q.post(subject, 'a', [1]), function (two) { + return Q.when(Q.post(subject, "a", [1]), function (two) { expect(subject._a).toBe(1); expect(two).toBe(2); }); @@ -635,7 +635,7 @@ describe("promises for objects", function () { return this.foo(_bar); } }; - return Q.send(subject, 'bar', 1, 2) + return Q.send(subject, "bar", 1, 2) .then(function (two) { expect(foo).toEqual(1); expect(two).toEqual(2); @@ -645,19 +645,19 @@ describe("promises for objects", function () { it("is rejected for undefined method", function () { var subject = {}; return Q.resolve(subject) - .send('foo') + .send("foo") .then(function () { expect("here").toEqual("not here"); - }, function (exception) { + }, function () { }); }); it("is rejected for undefined object", function () { return Q.resolve() - .send('foo') + .send("foo") .then(function () { expect("here").toEqual("not here"); - }, function (exception) { + }, function () { }); }); @@ -674,7 +674,7 @@ describe("promises for objects", function () { it("fulfills a promise", function () { return Q.keys(new Klass(10, 20)) .then(function (keys) { - expect(keys.sort()).toEqual(['a', 'b']); + expect(keys.sort()).toEqual(["a", "b"]); }); }); @@ -921,7 +921,7 @@ describe("promise states", function () { var parentPromise = deferred.promise; - var childPromise = parentPromise.then(function (value) { + var childPromise = parentPromise.then(function () { expect(parentPromise.isFulfilled()).toBe(true); expect(childPromise.isFulfilled()).toBe(false); @@ -1105,7 +1105,7 @@ describe("all", function () { .timeout(1000); }); - it("resolves foreign promises", function () { + it("resolves foreign thenables", function () { var normal = Q.resolve(1); var foreign = { then: function (f) { f(2); } }; @@ -1188,7 +1188,7 @@ describe("allResolved", function () { }); return Q.allResolved(promises) - .then(function (promises) { + .then(function () { expect(resolved).toBe(true); expect(rejected).toBe(true); }); @@ -1199,7 +1199,7 @@ describe("allResolved", function () { describe("spread", function () { it("spreads values across arguments", function () { - return Q.spread([1, 2, 3], function (a, b, c) { + return Q.spread([1, 2, 3], function (a, b) { expect(b).toBe(2); }); }); @@ -1346,7 +1346,7 @@ describe("fin", function () { .fin(function () { return "bar"; }) - .then(function (result) { + .then(function () { expect(false).toBe(true); }, function (exception) { @@ -1364,7 +1364,7 @@ describe("fin", function () { .fin(function () { return promise; }) - .then(function (result) { + .then(function () { expect(false).toBe(true); }, function (exception) { @@ -1376,13 +1376,11 @@ describe("fin", function () { describe("that is rejected", function () { it("should reject with the new reason", function () { - var newException = new TypeError("evil!"); - return Q.reject(exception1) .fin(function () { return Q.reject(exception2); }) - .then(function (result) { + .then(function () { expect(false).toBe(true); }, function (exception) { @@ -1562,7 +1560,6 @@ describe("timeout", function () { }); it("should reject with a timeout error if the promise is too slow", function () { - var goodError = new Error("haha!"); return Q.delay(100) .timeout(10) .then( @@ -1579,7 +1576,7 @@ describe("timeout", function () { var deferred = Q.defer(); var progressValsSeen = []; - var promise = Q.timeout(deferred.promise, 100).then(function () { + var promise = Q.timeout(deferred.promise, 300).then(function () { expect(progressValsSeen).toEqual([1, 2, 3]); }, undefined, function (progressVal) { progressValsSeen.push(progressVal); @@ -1594,7 +1591,6 @@ describe("timeout", function () { }); it("should reject with a custom timeout error if the promise is too slow and msg was provided", function () { - var goodError = new Error("haha!"); return Q.delay(100) .timeout(10, "custom") .then( @@ -1708,23 +1704,23 @@ describe("thenResolve", function () { .then(function () { waited = true; }) - .thenResolve('foo') + .thenResolve("foo") .then(function (val) { expect(waited).toBe(true); - expect(val).toBe('foo'); + expect(val).toBe("foo"); }); }); describe("based off a rejected promise", function () { it("does nothing, letting the rejection flow through", function () { - return Q.reject('boo') - .thenResolve('foo') + return Q.reject("boo") + .thenResolve("foo") .then( function () { expect(true).toBe(false); }, function (reason) { - expect(reason).toBe('boo'); + expect(reason).toBe("boo"); } ); }); @@ -1738,10 +1734,10 @@ describe("thenResolve", function () { .then(function () { waited = true; }) - .thenResolve(Q.resolve('foo')) + .thenResolve(Q.resolve("foo")) .then(function (val) { expect(waited).toBe(true); - expect(val).toBe('foo'); + expect(val).toBe("foo"); }); }); }); @@ -1755,28 +1751,28 @@ describe("thenReject", function () { .then(function () { waited = true; }) - .thenReject('foo') + .thenReject("foo") .then( function () { expect(true).toBe(false); }, function (reason) { expect(waited).toBe(true); - expect(reason).toBe('foo'); + expect(reason).toBe("foo"); } ); }); describe("based off a rejected promise", function () { it("does nothing, letting the rejection flow through", function () { - return Q.reject('boo') - .thenResolve('foo') + return Q.reject("boo") + .thenResolve("foo") .then( function () { expect(true).toBe(false); }, function (reason) { - expect(reason).toBe('boo'); + expect(reason).toBe("boo"); } ); }); @@ -1853,7 +1849,7 @@ describe("thenables", function () { it("assimilates a thenable in allResolved", function () { return Q.allResolved([ - {then: function (win, fail) { + {then: function (win) { win(10); }} ]) @@ -1866,7 +1862,7 @@ describe("thenables", function () { it("assimilates a pending thenable in allResolved", function () { return Q.allResolved([ - {then: function (win, fail) { + {then: function (win) { setTimeout(function () { win(10); }, 100); @@ -1895,12 +1891,12 @@ describe("node support", function () { errorCallbacker: function (a, b, c, callback) { callback(exception); }, - errorThrower: function (a, b, c, callback) { + errorThrower: function () { throw exception; } }; - describe("nfapply", function (done) { + describe("nfapply", function () { it("fulfills with callback result", function () { return Q.nfapply(function (a, b, c, callback) { @@ -1916,7 +1912,7 @@ describe("node support", function () { return Q.nfapply(function (a, b, c, callback) { callback(exception); }, [1, 2, 3]) - .then(function (sum) { + .then(function () { expect(true).toBe(false); }, function (_exception) { expect(_exception).toBe(exception); @@ -1940,7 +1936,7 @@ describe("node support", function () { return Q.nfcall(function (a, b, c, callback) { callback(exception); }, 1, 2, 3) - .then(function (sum) { + .then(function () { expect(true).toBe(false); }, function (_exception) { expect(_exception).toBe(exception); @@ -1985,7 +1981,7 @@ describe("node support", function () { }); }); - describe("npost", function (done) { + describe("npost", function () { it("fulfills with callback result", function () { return Q.npost(obj, "method", [1, 2, 3]) @@ -2003,7 +1999,7 @@ describe("node support", function () { it("rejects with callback error", function () { return Q.npost(obj, "errorCallbacker", [1, 2, 3]) - .then(function (sum) { + .then(function () { expect("blue").toBe("no, yellow!"); }, function (_exception) { expect(_exception).toBe(exception); @@ -2012,7 +2008,7 @@ describe("node support", function () { it("rejects with thrown error", function () { return Q.npost(obj, "errorThrower", [1, 2, 3]) - .then(function (sum) { + .then(function () { expect(true).toBe(false); }, function (_exception) { expect(_exception).toBe(exception); @@ -2029,7 +2025,7 @@ describe("node support", function () { }); - describe("nsend", function (done) { + describe("nsend", function () { it("fulfills with callback result", function () { return Q.nsend(obj, "method", 1, 2, 3) @@ -2047,7 +2043,7 @@ describe("node support", function () { it("rejects with callback error", function () { return Q.nsend(obj, "errorCallbacker", 1, 2, 3) - .then(function (sum) { + .then(function () { expect("blue").toBe("no, yellow!"); }, function (_exception) { expect(_exception).toBe(exception); @@ -2056,7 +2052,7 @@ describe("node support", function () { it("rejects with thrown error", function () { return Q.nsend(obj, "errorThrower", 1, 2, 3) - .then(function (sum) { + .then(function () { expect(true).toBe(false); }, function (_exception) { expect(_exception).toBe(exception); @@ -2098,7 +2094,7 @@ describe("node support", function () { var callback = deferred.makeNodeResolver(); var exception = new Error("Holy Exception of Anitoch"); callback(exception); - return deferred.promise.then(function (value) { + return deferred.promise.then(function () { expect(5).toBe(3); }, function (_exception) { expect(_exception).toBe(exception); @@ -2145,7 +2141,7 @@ describe("isPromise", function () { it("returns true if passed a promise", function () { expect(Q.isPromise(Q.resolve(10))).toBe(true); }); - + it("returns false if not passed a promise", function () { expect(Q.isPromise(undefined)).toBe(false); expect(Q.isPromise(null)).toBe(false); @@ -2169,7 +2165,7 @@ describe("isPromiseAlike", function () { then: function () {} })).toBe(true); }); - + it("returns false if not passed a promise like object", function () { expect(Q.isPromiseAlike(undefined)).toBe(false); expect(Q.isPromiseAlike(null)).toBe(false);