test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 'use strict';
  2. var Runnable = require('./runnable');
  3. var utils = require('./utils');
  4. var errors = require('./errors');
  5. var createInvalidArgumentTypeError = errors.createInvalidArgumentTypeError;
  6. var isString = utils.isString;
  7. module.exports = Test;
  8. /**
  9. * Initialize a new `Test` with the given `title` and callback `fn`.
  10. *
  11. * @public
  12. * @class
  13. * @extends Runnable
  14. * @param {String} title - Test title (required)
  15. * @param {Function} [fn] - Test callback. If omitted, the Test is considered "pending"
  16. */
  17. function Test(title, fn) {
  18. if (!isString(title)) {
  19. throw createInvalidArgumentTypeError(
  20. 'Test argument "title" should be a string. Received type "' +
  21. typeof title +
  22. '"',
  23. 'title',
  24. 'string'
  25. );
  26. }
  27. Runnable.call(this, title, fn);
  28. this.pending = !fn;
  29. this.type = 'test';
  30. }
  31. /**
  32. * Inherit from `Runnable.prototype`.
  33. */
  34. utils.inherits(Test, Runnable);
  35. Test.prototype.clone = function() {
  36. var test = new Test(this.title, this.fn);
  37. test.timeout(this.timeout());
  38. test.slow(this.slow());
  39. test.enableTimeouts(this.enableTimeouts());
  40. test.retries(this.retries());
  41. test.currentRetry(this.currentRetry());
  42. test.globals(this.globals());
  43. test.parent = this.parent;
  44. test.file = this.file;
  45. test.ctx = this.ctx;
  46. return test;
  47. };