helpers.js 816 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. * helpers.js: Tests helpers for the TimeSpan module.
  3. *
  4. * (C) Charlie Robbins
  5. * MIT LICENSE
  6. *
  7. */
  8. var assert = require('assert'),
  9. timeSpan = require('../lib/time-span')
  10. function capitalize(str) {
  11. return str.charAt(0).toUpperCase() + str.slice(1);
  12. }
  13. var helpers = exports,
  14. components = ['milliseconds', 'seconds', 'minutes', 'hours', 'days'];
  15. //
  16. // Tests all of the factory methods for the `TimeSpan` object:
  17. // `fromMilliseconds`, `fromSeconds`, etc.
  18. //
  19. exports.testFactories = function (num) {
  20. var context = {};
  21. components.forEach(function (component) {
  22. var method = 'from' + capitalize(component);
  23. context['the ' + method + '() method'] = function () {
  24. var value = timeSpan[method](num);
  25. assert.equal(value[component], num);
  26. }
  27. });
  28. return context;
  29. };