Permalink
Browse files

closing promise chains to make sure errors are thrown

  • Loading branch information...
1 parent cd2d94f commit 5402e53d6c429554131b4a8f3faa26f05776376d @bahmutov committed Feb 22, 2014
Showing with 21 additions and 7 deletions.
  1. +8 −5 qunit-promises.js
  2. +13 −2 test/node-tests.js
View
@@ -35,7 +35,7 @@
QUnit.push(true, undefined, undefined, message);
}, function () {
QUnit.push(false, undefined, undefined, 'promise rejected (but should have been resolved)');
- })[always](QUnit.start);
+ })[always](QUnit.start).done();
},
willEqual: function (promise, expected, message) {
@@ -46,18 +46,21 @@
QUnit.push(actual == expected, actual, expected, message);
}, function (actual) {
QUnit.push(false, actual, expected, 'promise rejected (but should have been resolved)');
- })[always](QUnit.start);
+ })[always](QUnit.start).done();
},
willDeepEqual: function (promise, expected, message) {
var always = verifyPromise(promise);
QUnit.stop();
promise.then(function (actual) {
+ if (typeof QUnit.equiv !== 'function') {
+ throw new Error('Missing QUnit.equiv function');
+ }
QUnit.push(QUnit.equiv(actual, expected), actual, expected, message);
}, function (actual) {
QUnit.push(false, actual, expected, 'promise rejected (but should have been resolved)');
- })[always](QUnit.start);
+ })[always](QUnit.start).done();
},
// rejected promises
@@ -69,7 +72,7 @@
QUnit.push(false, undefined, undefined, 'promise resolved (but should have been rejected)');
}, function () {
QUnit.push(true, undefined, undefined, message);
- })[always](QUnit.start);
+ })[always](QUnit.start).done();
},
wontEqual: function (promise, expected, message) {
@@ -80,7 +83,7 @@
QUnit.push(false, actual, expected, 'promise resolved (but should have been rejected)');
}, function (actual) {
QUnit.push(actual == expected, actual, expected, message);
- })[always](QUnit.start);
+ })[always](QUnit.start).done();
}
});
}(QUnit));
View
@@ -27,7 +27,10 @@ function delayedFoo() {
QUnit.test('example promise test', function (assert) {
assert.will(delayedFoo(), 'promise is resolved');
- assert.willEqual(delayedFoo(), 'foo', 'promise is resolved with correct value');
+});
+
+QUnit.test('example promise test with value', function (assert) {
+ assert.willEqual(delayedFoo(), 'foo', 'promise is resolved with correct value');
});
function delayedHello() {
@@ -54,6 +57,7 @@ function delayedOneFail() {
return deferred.promise;
}
+/*
function delayedFooBar() {
var deferred = Q.defer();
var result = {
@@ -64,6 +68,7 @@ function delayedFooBar() {
setTimeout(function () { deferred.resolve(result); }, 100);
return deferred.promise;
}
+*/
// regular custom code testing a successful promise
QUnit.test('test successful promise', 1, function (assert) {
@@ -87,10 +92,15 @@ QUnit.test('promise will resolve with value', 1, function (assert) {
assert.willEqual(delayedHello(), 'hello', 'returns "hello"');
});
-QUnit.test('compare value using deep equality', 1, function (assert) {
+QUnit.test('compare value using equality', 1, function (assert) {
assert.willEqual(delayedOne(), 1, 'returns 1');
});
+/*
+QUnit.test('QUnit.equiv', function (assert) {
+ assert.equal(typeof QUnit.equiv, 'function', 'QUnit.equiv is a function');
+});
+
QUnit.test('promise will resolve with value using deepEqual', function (assert) {
var expected = {
foo: {
@@ -99,6 +109,7 @@ QUnit.test('promise will resolve with value using deepEqual', function (assert)
};
assert.willDeepEqual(delayedFooBar(), expected, 'returns equal object');
});
+*/
// regular code to test failed promise
QUnit.test('test failed promise', 1, function (assert) {

0 comments on commit 5402e53

Please sign in to comment.