feat(utils.spec.qml): add a test on setTimeout

This commit is contained in:
Ronan Abhamon 2016-10-19 12:54:23 +02:00
parent e30574e07f
commit cb131ed71f
2 changed files with 39 additions and 1 deletions

View file

@ -97,7 +97,7 @@ function setTimeout (delay, cb) {
}
function clearTimeout (timer) {
timer.destroy() // Not necessary: `timer.stop()`
timer.destroy() // Unnecessary call: `timer.stop()`
}
// -------------------------------------------------------------------

View file

@ -5,7 +5,11 @@ import QtTest 1.1
// when tests are executed.
import './utils.js' as Utils
// ===================================================================
TestCase {
id: testCase
name: 'UtilsTests'
function test_snakeToCamel_data () {
@ -20,4 +24,38 @@ TestCase {
function test_snakeToCamel (data) {
compare(Utils.snakeToCamel(data.input), data.output)
}
function test_setTimeoutWithoutParent () {
try {
Utils.setTimeout(0, function () {
fail('`setTimeout` was called without parent.')
})
} catch (e) {
compare(e, 'Error: Qt.createQmlObject(): Missing parent object')
}
}
function test_setTimeout_data () {
return [
{ time: 0 },
{ time: 100 }
]
}
function test_setTimeout (data) {
var failed = true
Utils.setTimeout.call(testCase, data.time, function () {
failed = false
})
if (!failed) {
fail('`setTimeout` callback was called before `wait`')
}
wait(200)
if (failed) {
fail('`setTimeout` failed because callback it was not called in due course')
}
}
}