Skip to content

Commit

Permalink
Tests WIP 26 (major refactor)
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jul 8, 2016
1 parent 95d0c39 commit f373daa
Show file tree
Hide file tree
Showing 26 changed files with 972 additions and 825 deletions.
20 changes: 5 additions & 15 deletions test/methods/bind.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,19 @@
* Tests for Promise.bind() / .bind()
*/

/* global describe */

// Imports
var runTests = require('../support');

// Run tests

runTests('Promise.bind()', function(u, Promise) {
describe('returns instance of patched Promise constructor when passed', function() {
u.test('object', function(t) {
var p = Promise.bind({});
t.error(u.returnErrIfNotPromise(p));
t.done(p);
});
u.testSetStaticMethodReceivingValueReturnsPromise(function(value) {
return Promise.bind(value);
});
});

runTests('.bind()', function(u, Promise) {
describe('returns instance of patched Promise constructor when passed', function() {
u.test('object', function(t) {
var p = Promise.resolve().bind({});
t.error(u.returnErrIfNotPromise(p));
t.done(p);
});
runTests('.bind()', function(u) {
u.testSetProtoMethodReceivingValueReturnsPromise(function(p, value) {
return p.bind(value);
});
});
4 changes: 2 additions & 2 deletions test/methods/catch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var runTests = require('../support');

runTests('.catch()', function(u) {
describe('with 1st arg', function() {
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.catch(handler);
}, {catches: true});
});
Expand All @@ -25,7 +25,7 @@ runTests('.catch()', function(u) {
// `.catch()` calls `.then()` synchronously but with proxy handler.
// No way to test for binding.
// TODO Add more tests that handler runs in correct CLS context
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.catch(Error, handler);
}, {catches: true, noUndefined: true, noBindTest: (u.bluebirdVersion === 3)});
});
Expand Down
71 changes: 43 additions & 28 deletions test/methods/constructor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,65 @@ var runTests = require('../support');

runTests('new Promise()', function(u, Promise) {
describe('returns instance of patched Promise constructor when', function() {
u.test('resolved sync', function(t) {
var p = u.resolveSync();
t.error(u.returnErrIfNotPromise(p));
t.done(p);
});
u.describeResolveRejectSyncAsync(function(makePromise) {
u.testIsPromise(function() {
return makePromise();
});
}, Promise, {continues: true, catches: true});

u.test('resolved async', function(t) {
var p = u.resolveAsync();
t.error(u.returnErrIfNotPromise(p));
t.done(p);
/*
// TODO test for when resolved with promise e.g. `new Promise(function(resolve) { resolve(Promise.resolve(); )})`
describe('resolves with', function() {
testValues(function(value) {
return new Promise(function(resolve) {
resolve(value);
});
});
});
u.test('rejected sync', function(t) {
var p = u.rejectSync();
t.error(u.returnErrIfNotPromise(p));
t.done(p);
describe('rejects with', function() {
testValues(function(value) {
var p = new Promise(function(resolve, reject) { // jshint ignore:line
reject(value);
});
u.setRejectStatus(p);
return p;
});
});
u.test('rejected async', function(t) {
var p = u.rejectAsync();
t.error(u.returnErrIfNotPromise(p));
t.done(p);
});
function testValues(fn) {
u.describeValues(function(makeValue) {
u.testIsPromise(function() {
var value = makeValue();
var p = fn(value);
u.inheritRejectStatus(p, value);
return p;
});
});
}
*/

it('unresolved', function() {
it('unresolved', function(done) {
var p = new Promise(function() {});
u.throwIfNotPromise(p);
done(u.checkIsPromise(p));
});

u.test('handler throws', function(t) {
var p = new Promise(function() {
throw u.makeError();
describe('handler throws', function() {
u.testIsPromise(function() {
var p = new Promise(function() {
throw u.makeError();
});
u.setRejectStatus(p);
return p;
});

t.error(u.returnErrIfNotPromise(p));
t.done(p);
});
});

var testFn = function(handler) {
return new Promise(handler);
};

u.testSetCallbackSync(testFn, {handler: function(resolve) { resolve(); }});
u.testSetStaticCallbackSync(testFn, {handler: function(resolve) { resolve(); }});

u.testSetCallbackNotBound(testFn, {handler: function(resolve) { resolve(); }});
u.testSetStaticCallbackNotBound(testFn, {handler: function(resolve) { resolve(); }});
});
2 changes: 1 addition & 1 deletion test/methods/error.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ runTests('.error()', function(u) {
// `.error()` calls `.catch()` synchronously which calls `.then()` synchronously but with proxy handler.
// No way to test for binding.
// TODO Add more tests that handler runs in correct CLS context
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.error(handler);
}, {catches: true, noUndefined: true, noBindTest: (u.bluebirdVersion === 3)});
});
2 changes: 1 addition & 1 deletion test/methods/finally.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var runTests = require('../support');
// Run tests

runTests('.finally()', function(u) {
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.finally(handler);
}, {catches: true, continues: true, passThrough: true});
});
Expand Down
28 changes: 15 additions & 13 deletions test/methods/join.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ var runTests = require('../support');

// Run tests

// TODO Intersect two promise return test sets - test all combinations of promise values and handler return values.
// This will make it work like the collection method tests.
runTests('.join()', function(u, Promise) {
describe('returns instance of patched Promise constructor when resolving values are', function() {
u.testSetValueReturnsPromise(function(value) {
return Promise.join(value, value, value);
});
u.testSetStaticMethodReceivingValueReturnsPromise(function(value) {
return Promise.join(value, value, value);
});

/*
Expand All @@ -24,22 +24,24 @@ runTests('.join()', function(u, Promise) {
* So async calling test is performed separately to allow for this.
* TODO Change test once issue is fixed (if it is considered a bug).
*/
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return Promise.join(p, p, p, handler);
}, {noUndefined: true, noAsyncTest: true});

// Check callback called sync/async
describe('calls callback', function() {
u.test('synchronously when promises are resolved', function(t) {
u.checkSync(function(handler) {
return Promise.join(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3), handler);
}, t);
describe('synchronously when promises are resolved', function() {
u.testSync(function(handler, cb) {
var p = Promise.join(Promise.resolve(1), Promise.resolve(2), Promise.resolve(3), handler);
cb(p);
});
});

u.test('asynchronously when promises are pending', function(t) {
u.checkAsync(function(handler) {
return Promise.join(Promise.resolve(1), Promise.resolve(2).tap(function() {}), Promise.resolve(3), handler);
}, t);
describe('asynchronously when promises are pending', function() {
u.testAsync(function(handler, cb) {
var p = Promise.join(Promise.resolve(1), Promise.resolve(2).tap(function() {}), Promise.resolve(3), handler);
cb(p);
});
});
});
});
8 changes: 6 additions & 2 deletions test/methods/method.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
* Tests for Promise.method()
*/

/* global describe */

// Imports
var runTests = require('../support');

// Run tests

runTests('Promise.method()', function(u, Promise) {
u.testSetStaticMethodSync(function(handler) {
return (Promise.method(handler))();
describe('returns a function that', function() {
u.testSetStaticMethodSyncHandler(function(handler) {
return (Promise.method(handler))();
});
});
});
11 changes: 6 additions & 5 deletions test/methods/reject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ var runTests = require('../support');

runTests('Promise.reject()', function(u, Promise) {
describe('returns instance of patched Promise constructor when passed', function() {
u.test('error object', function(t) {
var p = Promise.reject(u.makeError());
u.setRejectStatus(p);
t.error(u.returnErrIfNotPromise(p));
t.done(p);
describe('error object', function() {
u.testIsPromise(function() {
var p = Promise.reject(u.makeError());
u.setRejectStatus(p);
return p;
});
});
});
});
Expand Down
8 changes: 3 additions & 5 deletions test/methods/resolve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Tests for Promise.resolve()
*/

/* global describe, it */
/* global it */

// Modules
var expect = require('chai').expect;
Expand All @@ -14,10 +14,8 @@ var runTests = require('../support');
// Run tests

runTests('Promise.resolve()', function(u, Promise) {
describe('returns instance of patched Promise constructor when passed', function() {
u.testSetValueReturnsPromise(function(value) {
return Promise.resolve(value);
});
u.testSetStaticMethodReceivingValueReturnsPromise(function(value) {
return Promise.resolve(value);
});
});

Expand Down
14 changes: 6 additions & 8 deletions test/methods/spread.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
* Tests for .spread()
*/

/* global describe */

// Imports
var runTests = require('../support');

// Run tests

// TODO tests for reject handler in bluebird v2
// TODO Tests for reject handler in bluebird v2
// TODO Intersect these two test sets - test all combinations of promise values and handler return values.
// This will make it work like the collection method tests.
runTests('.spread()', function(u, Promise) {
describe('returns instance of patched Promise constructor when passed array containing', function() {
u.testSetValueReturnsPromise(function(value) {
return Promise.resolve([value, value]).spread(function() {});
});
u.testSetStaticMethodReceivingValueReturnsPromise(function(value) {
return Promise.resolve([value, value]).spread(function() {});
});

u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.spread(handler);
}, {noUndefined: true});
});
4 changes: 2 additions & 2 deletions test/methods/then.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ var runTests = require('../support');

runTests('.then()', function(u) {
describe('resolve handler', function() {
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.then(handler);
});
});

describe('reject handler', function() {
u.testSetProtoMethodAsync(function(p, handler) {
u.testSetProtoMethodAsyncHandler(function(p, handler) {
return p.then(undefined, handler);
}, {catches: true});
});
Expand Down
2 changes: 1 addition & 1 deletion test/methods/try.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var runTests = require('../support');
// Run tests

runTests('Promise.try()', function(u, Promise) {
u.testSetStaticMethodSync(function(handler) {
u.testSetStaticMethodSyncHandler(function(handler) {
return Promise.try(handler);
});
});
Expand Down
Loading

0 comments on commit f373daa

Please sign in to comment.