hook.js 736 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use strict';
  2. var Runnable = require('./runnable');
  3. var inherits = require('./utils').inherits;
  4. /**
  5. * Expose `Hook`.
  6. */
  7. module.exports = Hook;
  8. /**
  9. * Initialize a new `Hook` with the given `title` and callback `fn`
  10. *
  11. * @class
  12. * @extends Runnable
  13. * @param {String} title
  14. * @param {Function} fn
  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. inherits(Hook, Runnable);
  24. /**
  25. * Get or set the test `err`.
  26. *
  27. * @memberof Hook
  28. * @public
  29. * @param {Error} err
  30. * @return {Error}
  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. };