Sorry to mention you <@U2E974ELT> but don’t you ha...
# coroutines
g
Sorry to mention you @elizarov but don’t you have an idea of how to do that?
e
What is that thenable promise that qunit needs? Why would a regular JS Promise not work?
(I’ve never tried qunit myself)
g
QUnit.test() can automatically handle the asynchronous resolution of a Promise on your behalf if you return a thenable Promise as the result of your callback function.
Qunit needs a
then
function on the promise.
g
When I run this code:
Copy code
@Test
    fun testPromise(): Promise<String> =
        promise {
            delay(1000)
            assertTrue(true)
            "OK"
        }
The result captured by qunit as
promise
is of type Unit and
promise.then
is undefined which causes the problem. When I do some plain javascript test (working):
Copy code
QUnit.test( "a Promise-returning test", function( assert ) {
    return new Promise(function (resolve, reject) {
        setTimeout(function () {
            assert.ok(true);
            resolve("result");
        }, 1500);
    });
});
promise
is a Promise object with
then
defined as a function.
Ok, I think I found the bug. It’s on FrameworkAdapter: https://github.com/JetBrains/kotlin/blob/e43a145614220fb0d2f596fb19ce28092965e794/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/FrameworkAdapter.kt#L52 The signature of
testFn
should be
()->Any
to give back the result of the test function call to Qunit, allowing it to manage an potential Promise.
e
Would you submit http://kotl.in/issue, please
g
e
Thanks a lot!
👍 1