-
Notifications
You must be signed in to change notification settings - Fork 52
/
test-Stopwatch.js
59 lines (46 loc) · 1.11 KB
/
test-Stopwatch.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
56
57
58
59
var common = require('../../common');
var test = require('utest');
var assert = require('assert');
var Stopwatch = common.betterMetrics.Stopwatch;
var sinon = require('sinon');
var watch;
var clock;
test('Stopwatch', {
before: function() {
clock = sinon.useFakeTimers();
watch = new Stopwatch();
},
after: function() {
clock.restore();
},
'returns time on end': function() {
clock.tick(10);
var watch = new Stopwatch();
clock.tick(100);
var elapsed = watch.end();
assert.equal(elapsed, 100);
},
'emits time on end': function() {
var watch = new Stopwatch();
clock.tick(20);
var time;
watch.on('end', function(_time) {
time = _time;
});
watch.end();
assert.equal(time, 20);
},
'becomes useless after being ended once': function() {
var watch = new Stopwatch();
clock.tick(20);
var time;
watch.on('end', function(_time) {
time = _time;
});
assert.equal(watch.end(), 20);
assert.equal(time, 20);
time = null;
assert.equal(watch.end(), undefined);
assert.equal(time, null);
},
});