From cb131ed71f9e14e8270c4c14679a9c3c9d47af4b Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 19 Oct 2016 12:54:23 +0200 Subject: [PATCH] feat(utils.spec.qml): add a test on `setTimeout` --- tests/ui/scripts/Utils/utils.js | 2 +- tests/ui/scripts/Utils/utils.spec.qml | 38 +++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/ui/scripts/Utils/utils.js b/tests/ui/scripts/Utils/utils.js index 32d1f0de4..92714738c 100644 --- a/tests/ui/scripts/Utils/utils.js +++ b/tests/ui/scripts/Utils/utils.js @@ -97,7 +97,7 @@ function setTimeout (delay, cb) { } function clearTimeout (timer) { - timer.destroy() // Not necessary: `timer.stop()` + timer.destroy() // Unnecessary call: `timer.stop()` } // ------------------------------------------------------------------- diff --git a/tests/ui/scripts/Utils/utils.spec.qml b/tests/ui/scripts/Utils/utils.spec.qml index f57cfc96c..609540541 100644 --- a/tests/ui/scripts/Utils/utils.spec.qml +++ b/tests/ui/scripts/Utils/utils.spec.qml @@ -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') + } + } }