Skip to content

Commit

Permalink
Convert all tests that can return a promise to promise-returning styl…
Browse files Browse the repository at this point in the history
…e. done() callbacks be gone! Only cram tests still need done() style
  • Loading branch information
briancavalier committed Jul 16, 2013
1 parent 6c7e2ee commit b9822c7
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 221 deletions.
6 changes: 3 additions & 3 deletions test/node/ComponentFactory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sentinel = {};
buster.testCase('lib/ComponentFactory', {

"create": {
'should call factory': function(done) {
'should call factory': function() {
var cf, factory, options;

cf = new ComponentFactory({}, {}, { contextualize: this.stub().returns({}) });
Expand All @@ -27,11 +27,11 @@ buster.testCase('lib/ComponentFactory', {
options = {};
cf.getFactory = this.stub().returns({ factory: factory, options: options });

cf.create({}).then(
return cf.create({}).then(
function(instance) {
assert.same(instance, sentinel);
}
).then(done, done);
);
}
},

Expand Down
84 changes: 42 additions & 42 deletions test/node/aop-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ buster.testCase('aop', {

'around': {

'should execute function around method': function(done) {
'should execute function around method': function() {
var beforeSpy, afterSpy;

beforeSpy = this.spy();
Expand All @@ -124,7 +124,7 @@ buster.testCase('aop', {
afterSpy(joinpoint.proceed());
}

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -144,17 +144,17 @@ buster.testCase('aop', {
assert.calledOnceWith(afterSpy, sentinel);
},
fail
).then(done, done);
);
}

},

'afterReturning': {

'should execute function after method returns': function(done) {
'should execute function after method returns': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -177,13 +177,13 @@ buster.testCase('aop', {
assert.calledOnceWith(spy, sentinel);
},
fail
).then(done, done);
);
},

'should not execute function after method throws': function(done) {
'should not execute function after method throws': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -207,16 +207,16 @@ buster.testCase('aop', {
refute.called(spy);
},
fail
).then(done, done);
);
}
},

'afterThrowing': {

'should execute function after method throws': function(done) {
'should execute function after method throws': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -239,13 +239,13 @@ buster.testCase('aop', {
function() {
assert.calledOnceWith(spy, sentinel);
}
).then(done, done);
);
},

'should not execute function after method returns': function(done) {
'should not execute function after method returns': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -264,16 +264,16 @@ buster.testCase('aop', {
refute.called(spy);
},
fail
).then(done, done);
);
}
},

'after': {

'should execute function after method returns': function(done) {
'should execute function after method returns': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -296,13 +296,13 @@ buster.testCase('aop', {
assert.calledOnceWith(spy, sentinel);
},
fail
).then(done, done);
);
},

'should execute function after method throws': function(done) {
'should execute function after method throws': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -325,17 +325,17 @@ buster.testCase('aop', {
function() {
assert.calledOnceWith(spy, sentinel);
}
).then(done, done);
);
}
},

'that is promise-aware': {

'afterFulfilling': {
'should execute function after returned promise is fulfilled': function(done) {
'should execute function after returned promise is fulfilled': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -358,13 +358,13 @@ buster.testCase('aop', {
assert.calledOnceWith(spy, sentinel);
},
fail
).then(done, done);
);
},

'should not execute function after returned promise is rejected': function(done) {
'should not execute function after returned promise is rejected': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -387,15 +387,15 @@ buster.testCase('aop', {
function() {
refute.called(spy);
}
).then(done, done);
);
}
},

'afterRejecting': {
'should execute function after returned promise is rejected': function(done) {
'should execute function after returned promise is rejected': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -418,13 +418,13 @@ buster.testCase('aop', {
function() {
assert.calledOnceWith(spy, sentinel);
}
).then(done, done);
);
},

'should not execute function after returned promise is fulfilled': function(done) {
'should not execute function after returned promise is fulfilled': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -447,15 +447,15 @@ buster.testCase('aop', {
refute.called(spy);
},
fail
).then(done, done);
);
}
},

'after': {
'should execute function after returned promise is fulfilled': function(done) {
'should execute function after returned promise is fulfilled': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -478,13 +478,13 @@ buster.testCase('aop', {
assert.calledOnceWith(spy, sentinel);
},
fail
).then(done, done);
);
},

'should execute function after returned promise is rejected': function(done) {
'should execute function after returned promise is rejected': function() {
var spy = this.spy();

wire({
return wire({
plugins: [aopPlugin],
target: {
literal: {
Expand All @@ -507,14 +507,14 @@ buster.testCase('aop', {
function() {
assert.calledOnceWith(spy, sentinel);
}
).then(done, done);
);
}
}
}
},

'weaving': {
'should weave aspects': function(done) {
'should weave aspects': function() {
function aspect() {
return {
pointcut: /^doSomething$/,
Expand All @@ -539,7 +539,7 @@ buster.testCase('aop', {
doOneMoreThing: function() { return 0; }
};

wire({
return wire({
plugins: [
{
wire$plugin: aopPlugin,
Expand Down Expand Up @@ -572,7 +572,7 @@ buster.testCase('aop', {
assert.equals(t1.doOneMoreThing(), 0);
assert.equals(t2.doOneMoreThing(), 0);
}
).then(done, done);
);
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions test/node/circular-refs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ buster.testCase('circular-refs', {
delete plugin.wire$plugin;
},

'should resolve circular deps after init has finished': function(done) {
'should resolve circular deps after init has finished': function() {
var promise = timeout(wire({
plugins: [{ module: './test/node/fixtures/object' }],
component1: {
Expand All @@ -47,13 +47,13 @@ buster.testCase('circular-refs', {
}
}), 100);

promise.then(
return promise.then(
function(context) {
assert.defined(context.component1);
assert.defined(context.component2);
},
fail
).then(done, done);
);
},

'should not resolve circular deps before init has finished': function() {
Expand Down
24 changes: 12 additions & 12 deletions test/node/debug-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,47 @@ buster.testCase('wire/debug', {
console.log = log;
},

'should set constructor on constructor-less object components': function(done) {
wire({
'should set constructor on constructor-less object components': function() {
return wire({
plugins: [debugPlugin],
myComponent: {
create: './test/node/fixtures/object'
}
}).then(function(context) {
assert.isFunction(context.myComponent.constructor);
assert.equals(context.myComponent.constructor.name, 'myComponent');
}).then(done, done);
});
},

'should set not constructor on components that already have one': function(done) {
wire({
'should set not constructor on components that already have one': function() {
return wire({
plugins: [debugPlugin],
myComponent: {
create: './test/node/fixtures/constructor'
}
}).then(function(context) {
assert.isFunction(context.myComponent.constructor);
refute.equals(context.myComponent.constructor.name, 'myComponent');
}).then(done, done);
});
},

'should not set constructor on non-object components': function(done) {
wire({
'should not set constructor on non-object components': function() {
return wire({
plugins: [debugPlugin],
myComponent: 'just a string'
}).then(function(context) {
refute.equals(context.myComponent.constructor.name, 'myComponent');
}).then(done, done);
});
},

'should not set constructor when not active': function(done) {
wire({
'should not set constructor when not active': function() {
return wire({
myComponent: {
create: './test/node/fixtures/object'
}
}).then(function(context) {
refute.equals(context.myComponent.constructor.name, 'myComponent');
}).then(done, done);
});
}

});
Expand Down
Loading

0 comments on commit b9822c7

Please sign in to comment.