hook.js 714 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Module dependencies.
  3. */
  4. var Runnable = require('./runnable');
  5. /**
  6. * Expose `Hook`.
  7. */
  8. module.exports = Hook;
  9. /**
  10. * Initialize a new `Hook` with the given `title` and callback `fn`.
  11. *
  12. * @param {String} title
  13. * @param {Function} fn
  14. * @api private
  15. */
  16. function Hook(title, fn) {
  17. Runnable.call(this, title, fn);
  18. this.type = 'hook';
  19. }
  20. /**
  21. * Inherit from `Runnable.prototype`.
  22. */
  23. Hook.prototype.__proto__ = Runnable.prototype;
  24. /**
  25. * Get or set the test `err`.
  26. *
  27. * @param {Error} err
  28. * @return {Error}
  29. * @api public
  30. */
  31. Hook.prototype.error = function(err){
  32. if (0 == arguments.length) {
  33. var err = this._error;
  34. this._error = null;
  35. return err;
  36. }
  37. this._error = err;
  38. };