@@ -37,8 +37,16 @@ def to_raise(msg):
3737 # `setTimeout` should allow passing additional arguments to the callback, as spec-ed
3838 assert 3.0 == await pm .eval ("new Promise((resolve) => setTimeout(function(){ resolve(arguments.length) }, 100, 90, 91, 92))" )
3939 assert 92.0 == await pm .eval ("new Promise((resolve) => setTimeout((...args) => { resolve(args[2]) }, 100, 90, 91, 92))" )
40- # TODO (Tom Tang): test `setTimeout` setting delay to 0 if < 0
41- # TODO (Tom Tang): test `setTimeout` accepting string as the delay, coercing to a number like parseFloat
40+ # test `setTimeout` setting delay to 0 if < 0
41+ await asyncio .wait_for (pm .eval ("new Promise((resolve) => setTimeout(resolve, 0))" ), timeout = 0.02 )
42+ await asyncio .wait_for (pm .eval ("new Promise((resolve) => setTimeout(resolve, -10000))" ), timeout = 0.02 ) # won't be precisely 0s
43+ # test `setTimeout` accepting string as the delay, coercing to a number.
44+ # Number('100') -> 100, pass if the actual delay is > 90ms and < 120ms
45+ await asyncio .wait_for (pm .eval ("new Promise((resolve) => setTimeout(resolve, '100'))" ), timeout = 0.12 ) # won't be precisely 100ms
46+ with pytest .raises (asyncio .exceptions .TimeoutError ):
47+ await asyncio .wait_for (pm .eval ("new Promise((resolve) => setTimeout(resolve, '100'))" ), timeout = 0.09 )
48+ # Number("1 second") -> NaN -> delay turns to be 0s
49+ await asyncio .wait_for (pm .eval ("new Promise((resolve) => setTimeout(resolve, '1 second'))" ), timeout = 0.02 ) # won't be precisely 0s
4250
4351 # passing an invalid ID to `clearTimeout` should silently do nothing; no exception is thrown.
4452 pm .eval ("clearTimeout(NaN)" )
0 commit comments