hook.js 792 B

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