forked from popomore/schedule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
55 lines (48 loc) · 1.4 KB
/
test.js
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
var every = require('./index').every;
var should = require('should');
var sinon = require('sinon');
describe('Timers', function() {
it('string parse', function() {
every('10ms').time.should.be.eql(10);
every('2s').time.should.be.eql(2000);
every('2.5m').time.should.be.eql(150000);
every('2h').time.should.be.eql(7200000);
every('2d').time.should.be.eql(172800000);
});
it('string parse format', function() {
every('2hour').time.should.be.eql(7200000);
every('2 hour').time.should.be.eql(7200000);
every('2 hours').time.should.be.eql(7200000);
every(' 2 day ').time.should.be.eql(172800000);
every('2days ').time.should.be.eql(172800000);
should.not.exist(every(' 2 unknown').time);
});
it('every', function(done) {
var spy = sinon.spy();
var e = every('50ms').do(spy);
setTimeout(function() {
spy.calledOn(e);
spy.callCount.should.be.eql(1);
}, 55);
setTimeout(function() {
spy.callCount.should.be.eql(2);
}, 110);
setTimeout(function() {
spy.callCount.should.be.eql(3);
done();
}, 165);
});
it('every stop', function(done) {
var spy = sinon.spy();
var e = every('50ms').do(spy);
setTimeout(function() {
spy.calledOn(e);
spy.callCount.should.be.eql(1);
e.stop();
}, 55);
setTimeout(function() {
spy.callCount.should.be.eql(1);
done();
}, 105);
});
});