Standard timers - fix for #4384 (#4389)

Specifications define timers capable of accepting optional parameters.
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#timers

This PR goal is to standardize such behavior in NativeScript too.
This commit is contained in:
Andrea Giammarchi
2017-06-15 21:19:49 +01:00
committed by Alexander Vakrilov
parent 9866350559
commit 7e39bfb9d4
4 changed files with 51 additions and 10 deletions

View File

@@ -39,6 +39,23 @@ export function test_setTimeout() {
TKUnit.assert(completed, "Callback should be called!");
};
export function test_setTimeout_extraArgs() {
let completed: boolean;
let rnd: number = Math.random();
// >> timer-set-zero
const id = timer.setTimeout((arg) => {
// >> (hide)
completed = rnd === arg;
// << (hide)
}, 0, rnd);
// << timer-set-zero
TKUnit.waitUntilReady(() => completed, 0.5, false);
timer.clearTimeout(id);
TKUnit.assert(completed, "Callback called with expected argument!");
};
export function test_setTimeout_callbackCalledAfterSpecifiedTime() {
let completed = false;
@@ -110,6 +127,24 @@ export function test_setInterval_callbackCalledDuringPeriod() {
TKUnit.assert(counter >= expected, "Callback should be raised at least" + expected + "times! Callback raised " + counter + " times.");
};
export function test_setInterval_callbackCalledWithExtraArgs() {
let counter: number = 0;
let expected: number = 4;
let rnd: number = Math.random();
// >> timer-set-expression
const id = timer.setInterval((arg) => {
// >> (hide)
counter += arg === rnd ? 1 : -1;
// << (hide)
}, 50, rnd);
// << timer-set-expression
TKUnit.waitUntilReady(() => counter >= expected, 0.25, false);
timer.clearInterval(id);
TKUnit.assert(counter >= expected, "Callback raised " + counter + " times with arguments.");
};
export function test_setInterval_callbackShouldBeCleared() {
let counter = 0;