date-convenience-methods-test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. var sinon = require('sinon');
  3. var main = require('../package.json').main;
  4. var schedule = require('../' + main);
  5. var clock;
  6. module.exports = {
  7. setUp: function(cb) {
  8. clock = sinon.useFakeTimers();
  9. cb();
  10. },
  11. "Date string": {
  12. "Should accept a valid date string": function(test) {
  13. test.expect(1);
  14. schedule.scheduleJob(new Date(Date.now() + 1000).toString(), function() {
  15. test.ok(true);
  16. });
  17. setTimeout(function() {
  18. test.done();
  19. }, 1250);
  20. clock.tick(1250);
  21. },
  22. "Should not accept invalid string as valid date": function(test) {
  23. test.expect(1);
  24. var job = schedule.scheduleJob("hello!!", function() {
  25. });
  26. test.equal(job, null);
  27. test.done();
  28. }
  29. },
  30. "UTC": {
  31. "Should accept a valid UTC date in milliseconds": function(test) {
  32. test.expect(1);
  33. schedule.scheduleJob(new Date(Date.now() + 1000).getTime(), function() {
  34. test.ok(true);
  35. });
  36. setTimeout(function() {
  37. test.done();
  38. }, 1250);
  39. clock.tick(1250);
  40. }
  41. },
  42. tearDown: function(cb) {
  43. clock.restore();
  44. cb();
  45. }
  46. };