mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
add tests
This commit is contained in:
@ -171,6 +171,31 @@ export function test_setInterval_callbackCalledWithExtraArgs(done) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function test_setInterval_callbackNotDelayedByBusyWork() {
|
||||||
|
let calls = 0;
|
||||||
|
|
||||||
|
function busyWait(ms: number) {
|
||||||
|
const waitStart = Date.now();
|
||||||
|
while (true) {
|
||||||
|
if (Date.now() - waitStart >= ms) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let firstCall = true;
|
||||||
|
const id = timer.setInterval(() => {
|
||||||
|
calls++;
|
||||||
|
if (firstCall) {
|
||||||
|
firstCall = false;
|
||||||
|
busyWait(25);
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
TKUnit.wait(0.11);
|
||||||
|
timer.clearInterval(id);
|
||||||
|
TKUnit.assertEqual(calls, 2, 'Callback should be called multiple times with busy wait');
|
||||||
|
}
|
||||||
|
|
||||||
export function test_setInterval_callbackShouldBeCleared(done) {
|
export function test_setInterval_callbackShouldBeCleared(done) {
|
||||||
const start = TKUnit.time();
|
const start = TKUnit.time();
|
||||||
// >> timer-set-interval
|
// >> timer-set-interval
|
||||||
|
Reference in New Issue
Block a user