hook.js 726 B

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