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