1 var assert = require('assert');
2 var Kareem = require('../');
4 describe('execPost', function() {
7 beforeEach(function() {
11 it('handles errors', function(done) {
12 hooks.post('cook', function(eggs, callback) {
16 hooks.execPost('cook', null, [4], function(error, eggs) {
17 assert.equal('error!', error);
23 it('multiple posts', function(done) {
24 hooks.post('cook', function(eggs, callback) {
32 hooks.post('cook', function(eggs, callback) {
40 hooks.execPost('cook', null, [4], function(error, eggs) {
41 assert.ifError(error);
42 assert.equal(4, eggs);
47 it('error posts', function(done) {
49 hooks.post('cook', function(eggs, callback) {
54 hooks.post('cook', function(eggs, callback) {
56 callback(new Error('fail'));
59 hooks.post('cook', function(eggs, callback) {
63 hooks.post('cook', function(error, eggs, callback) {
65 assert.equal(error.message, 'fail');
66 callback(new Error('fourth'));
69 hooks.post('cook', function(error, eggs, callback) {
71 assert.equal(error.message, 'fourth');
72 callback(new Error('fifth'));
75 hooks.execPost('cook', null, [4], function(error, eggs) {
77 assert.equal(error.message, 'fifth');
78 assert.deepEqual(called, {
88 it('error posts with initial error', function(done) {
91 hooks.post('cook', function(eggs, callback) {
95 hooks.post('cook', function(error, eggs, callback) {
97 assert.equal(error.message, 'fail');
98 callback(new Error('second'));
101 hooks.post('cook', function(error, eggs, callback) {
103 assert.equal(error.message, 'second');
104 callback(new Error('third'));
107 hooks.post('cook', function(error, eggs, callback) {
108 called.fourth = true;
109 assert.equal(error.message, 'third');
113 var options = { error: new Error('fail') };
114 hooks.execPost('cook', null, [4], options, function(error, eggs) {
116 assert.equal(error.message, 'third');
117 assert.deepEqual(called, {
127 describe('execPostSync', function() {
130 beforeEach(function() {
131 hooks = new Kareem();
134 it('executes hooks synchronously', function() {
137 hooks.post('cook', function() {
141 hooks.post('cook', function() {
142 execed.second = true;
145 hooks.execPostSync('cook', null);
146 assert.ok(execed.first);
147 assert.ok(execed.second);
150 it('works with no hooks specified', function() {
151 assert.doesNotThrow(function() {
152 hooks.execPostSync('cook', null);