Skip to content
Browse files

Add more love to tests, pr #249

  • Loading branch information...
1 parent 76c7fbd commit f36372ba806e59bc16be847cf3b2252c8b4ee333 @1602 committed Mar 31, 2013
Showing with 14 additions and 12 deletions.
  1. +14 −12 test/hooks.test.js
View
26 test/hooks.test.js
@@ -217,25 +217,26 @@ describe('hooks', function() {
});
});
- it('afterUpdate should not be triggered on failed save', function(done) {
+ it('should not trigger after-hook on failed save', function(done) {
User.afterUpdate = function() {
- throw new Error('shouldn\'t be called')
+ should.fail('afterUpdate shouldn\'t be called')
};
User.create(function (err, user) {
- var old = User.schema.adapter.save;
+ var save = User.schema.adapter.save;
User.schema.adapter.save = function(modelName, id, cb) {
- cb(new Error('error'));
+ User.schema.adapter.save = save;
+ cb(new Error('Error'));
}
user.save(function(err) {
- User.schema.adapter.save = old;
done();
});
});
});
});
describe('destroy', function() {
+
afterEach(removeHooks('Destroy'));
it('should be triggered on destroy', function(done) {
@@ -244,30 +245,31 @@ describe('hooks', function() {
hook = 'called';
next();
};
- User.afterDestroy = function() {
+ User.afterDestroy = function(next) {
hook.should.eql('called');
- done();
+ next();
};
User.create(function (err, user) {
- user.destroy();
+ user.destroy(done);
});
});
- it('afterDestroy should not be triggered on failed destroy', function(done) {
- var old = User.schema.adapter.destroy;
+ it('should not trigger after-hook on failed destroy', function(done) {
+ var destroy = User.schema.adapter.destroy;
User.schema.adapter.destroy = function(modelName, id, cb) {
cb(new Error('error'));
}
User.afterDestroy = function() {
- throw new Error('shouldn\'t be called')
+ should.fail('afterDestroy shouldn\'t be called')
};
User.create(function (err, user) {
user.destroy(function(err) {
- User.schema.adapter.destroy = old;
+ User.schema.adapter.destroy = destroy;
done();
});
});
});
+
});
describe('lifecycle', function() {

0 comments on commit f36372b

Please sign in to comment.
Something went wrong with that request. Please try again.