@@ -46,9 +46,40 @@ describe('Runnable(title, fn)', function() {
4646 } ) ;
4747
4848 describe ( '#timeout(ms)' , function ( ) {
49- var INT_MAX = 2147483647 ; // (32-bit signed integer)
49+ var MIN_TIMEOUT = 0 ;
50+ var MAX_TIMEOUT = 2147483647 ; // INT_MAX (32-bit signed integer)
5051
51- describe ( 'when value is less than `setTimeout` limit' , function ( ) {
52+ describe ( 'when value is less than lower bound' , function ( ) {
53+ it ( 'should clamp to lower bound given numeric' , function ( ) {
54+ var run = new Runnable ( ) ;
55+ run . timeout ( - 1 ) ;
56+ assert ( run . timeout ( ) === MIN_TIMEOUT ) ;
57+ } ) ;
58+ // :TODO: Our internal version of `ms` can't handle negative time,
59+ // but package version can. Skip this check until that change is merged.
60+ it . skip ( 'should clamp to lower bound given timestamp' , function ( ) {
61+ var run = new Runnable ( ) ;
62+ run . timeout ( '-1 ms' ) ;
63+ assert ( run . timeout ( ) === MIN_TIMEOUT ) ;
64+ } ) ;
65+ } ) ;
66+
67+ describe ( 'when value is equal to lower bound' , function ( ) {
68+ it ( 'should set the value and disable timeouts given numeric' , function ( ) {
69+ var run = new Runnable ( ) ;
70+ run . timeout ( MIN_TIMEOUT ) ;
71+ assert ( run . timeout ( ) === MIN_TIMEOUT ) ;
72+ assert ( run . enableTimeouts ( ) === false ) ;
73+ } ) ;
74+ it ( 'should set the value and disable timeouts given timestamp' , function ( ) {
75+ var run = new Runnable ( ) ;
76+ run . timeout ( MIN_TIMEOUT + 'ms' ) ;
77+ assert ( run . timeout ( ) === MIN_TIMEOUT ) ;
78+ assert ( run . enableTimeouts ( ) === false ) ;
79+ } ) ;
80+ } ) ;
81+
82+ describe ( 'when value is within `setTimeout` bounds' , function ( ) {
5283 var oneSecond = 1000 ;
5384
5485 it ( 'should set the timeout given numeric' , function ( ) {
@@ -65,30 +96,32 @@ describe('Runnable(title, fn)', function() {
6596 } ) ;
6697 } ) ;
6798
68- describe ( 'when value is equal to `setTimeout` limit ' , function ( ) {
69- it ( 'should set the timeout given numeric' , function ( ) {
99+ describe ( 'when value is equal to upper bound ' , function ( ) {
100+ it ( 'should set the value and disable timeout given numeric' , function ( ) {
70101 var run = new Runnable ( ) ;
71- run . timeout ( INT_MAX ) ;
72- assert ( run . timeout ( ) === INT_MAX ) ;
73- assert ( run . enableTimeouts ( ) === true ) ;
102+ run . timeout ( MAX_TIMEOUT ) ;
103+ assert ( run . timeout ( ) === MAX_TIMEOUT ) ;
104+ assert ( run . enableTimeouts ( ) === false ) ;
74105 } ) ;
75- it ( 'should set the timeout given timestamp' , function ( ) {
106+ it ( 'should set the value and disable timeout given timestamp' , function ( ) {
76107 var run = new Runnable ( ) ;
77- run . timeout ( INT_MAX + 'ms' ) ;
78- assert ( run . timeout ( ) === INT_MAX ) ;
79- assert ( run . enableTimeouts ( ) === true ) ;
108+ run . timeout ( MAX_TIMEOUT + 'ms' ) ;
109+ assert ( run . timeout ( ) === MAX_TIMEOUT ) ;
110+ assert ( run . enableTimeouts ( ) === false ) ;
80111 } ) ;
81112 } ) ;
82113
83114 describe ( 'when value is greater than `setTimeout` limit' , function ( ) {
84- it ( 'should disable timeouts given numeric' , function ( ) {
115+ it ( 'should clamp to upper bound given numeric' , function ( ) {
85116 var run = new Runnable ( ) ;
86- run . timeout ( INT_MAX + 1 ) ;
117+ run . timeout ( MAX_TIMEOUT + 1 ) ;
118+ assert ( run . timeout ( ) === MAX_TIMEOUT ) ;
87119 assert ( run . enableTimeouts ( ) === false ) ;
88120 } ) ;
89- it ( 'should disable timeouts given timestamp' , function ( ) {
121+ it ( 'should clamp to upper bound given timestamp' , function ( ) {
90122 var run = new Runnable ( ) ;
91123 run . timeout ( '24.9d' ) ; // 2151360000ms
124+ assert ( run . timeout ( ) === MAX_TIMEOUT ) ;
92125 assert ( run . enableTimeouts ( ) === false ) ;
93126 } ) ;
94127 } ) ;
0 commit comments