diff --git a/tests/app/timer/timer-tests.ts b/tests/app/timer/timer-tests.ts index c8c8a55d6..2c6f7997f 100644 --- a/tests/app/timer/timer-tests.ts +++ b/tests/app/timer/timer-tests.ts @@ -72,6 +72,23 @@ export function test_setTimeout_callbackCalledAfterSpecifiedTime() { TKUnit.assert(completed, "Callback should be called after the specified time!"); } +export function test_setTimeout_callbackCalledWithBooleanPeriod() { + let completed = false; + + // >> timer-set-false + const id = timer.setTimeout(() => { + // >> (hide) + completed = true; + // << (hide) + // @ts-ignore + }, false); + // << timer-set-false + + TKUnit.waitUntilReady(() => completed, 1); + timer.clearTimeout(id); + TKUnit.assert(completed, "Callback should be called in 0 seconds!"); +} + export function test_setTimeout_callbackNotCalled() { let completed = false; diff --git a/tns-core-modules/timer/timer.android.ts b/tns-core-modules/timer/timer.android.ts index 672dfb423..f18b81567 100644 --- a/tns-core-modules/timer/timer.android.ts +++ b/tns-core-modules/timer/timer.android.ts @@ -16,6 +16,9 @@ function createHandlerAndGetId(): number { } export function setTimeout(callback: Function, milliseconds = 0, ...args): number { + // Cast to Number + milliseconds += 0; + const id = createHandlerAndGetId(); const invoke = () => callback(...args); const zoneBound = zonedCallback(invoke); @@ -48,6 +51,9 @@ export function clearTimeout(id: number): void { } export function setInterval(callback: Function, milliseconds = 0, ...args): number { + // Cast to Number + milliseconds += 0; + const id = createHandlerAndGetId(); const handler = timeoutHandler; const invoke = () => callback(...args); diff --git a/tns-core-modules/timer/timer.ios.ts b/tns-core-modules/timer/timer.ios.ts index 7436cba95..777c7fa21 100644 --- a/tns-core-modules/timer/timer.ios.ts +++ b/tns-core-modules/timer/timer.ios.ts @@ -48,6 +48,9 @@ class TimerTargetImpl extends NSObject { } function createTimerAndGetId(callback: Function, milliseconds: number, shouldRepeat: boolean): number { + // Cast to Number + milliseconds += 0; + timerId++; let id = timerId; let timerTarget = TimerTargetImpl.initWithCallback(callback, id, shouldRepeat);