Skip to content

Commit 8ddb12c

Browse files
committed
Use proper type on if statement.
Periodic reminder that the number 0 evaluates to false in JavaScript. fix #15
1 parent f4ddd75 commit 8ddb12c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

jquery.simple.timer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@
103103
var secondsLeft = element.data('seconds-left');
104104
var minutesLeft = element.data('minutes-left');
105105

106-
if(secondsLeft){
106+
if(Number.isFinite(secondsLeft)){
107107
return parseInt(secondsLeft, 10);
108-
} else if(minutesLeft) {
108+
} else if(Number.isFinite(minutesLeft)) {
109109
return parseFloat(minutesLeft) * 60;
110110
}else {
111111
throw 'Missing time data';

tests/tests.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,35 @@ asyncTest('Clears the timer when complete and with options', function () {
7474
});
7575
});
7676

77+
78+
asyncTest('Cleas the timer when 0 minutes left', function () {
79+
expect(1);
80+
81+
var timerElement = $('#timer1');
82+
timerElement.data('minutes-left', 0);
83+
84+
var plugin = timerElement.startTimer({});
85+
86+
setTimeout(function() {
87+
equal(timerElement.text(), '00:00:00', 'Cleared timer');
88+
start();
89+
}, 1000);
90+
});
91+
92+
asyncTest('Clears the timer when 0 seconds left', function () {
93+
expect(1);
94+
95+
var timerElement = $('#timer1');
96+
timerElement.data('seconds-left', 0);
97+
98+
var plugin = timerElement.startTimer({});
99+
100+
setTimeout(function() {
101+
equal(timerElement.text(), '00:00:00', 'Cleared timer');
102+
start();
103+
}, 1000);
104+
});
105+
77106
asyncTest('Do not restart timer when loop option is false', function() {
78107
expect(1);
79108

0 commit comments

Comments
 (0)