Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail when test resolution method is overspecified #1320

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/runnable.js
Expand Up @@ -181,7 +181,8 @@ Runnable.prototype.run = function(fn){
, start = new Date
, ctx = this.ctx
, finished
, emitted;
, emitted
, result;

// Some times the ctx exists but it is not runnable
if (ctx && ctx.runnable) ctx.runnable(this);
Expand Down Expand Up @@ -213,7 +214,7 @@ Runnable.prototype.run = function(fn){
this.resetTimeout();

try {
this.fn.call(ctx, function(err){
result = this.fn.call(ctx, function(err){
if (err instanceof Error || toString.call(err) === "[object Error]") return done(err);
if (null != err) {
if (Object.prototype.toString.call(err) === '[object Object]') {
Expand All @@ -224,6 +225,10 @@ Runnable.prototype.run = function(fn){
}
done();
});

if (result && typeof result.then === 'function') {
return done(new Error('Asynchronous resolution method is overspecified. Specify a callback *or* return a Promise, not both.'));
}
} catch (err) {
done(err);
}
Expand Down
8 changes: 8 additions & 0 deletions test/acceptance/overspecified-async.js
@@ -0,0 +1,8 @@
describe('overspecified asynchronous resolution method', function() {
it('should fail when multiple methods are used', function(done) {
setTimeout(done, 0);

// uncomment
// return { then: function() {} };
});
});