[JS] Support custom Promise declarations for kotlin.test @AfterTest
^KT-63359 fixed Merge-request: KT-MR-14001 Merged-by: Anton Bannykh <Anton.Bannykh@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
9a74a5fcdd
commit
245409dede
@@ -4,6 +4,7 @@ module.exports = {
|
||||
'SimpleTest testFooWrong': 'pending',
|
||||
'TestTest emptyTest': 'pending',
|
||||
'AsyncTest checkAsyncOrder': 'pass',
|
||||
'AsyncTest checkCustomPromise': 'pass',
|
||||
'AsyncTest asyncPassing': 'pass',
|
||||
'AsyncTest asyncFailing': 'fail',
|
||||
'org OrgTest test': 'pass',
|
||||
|
||||
@@ -46,28 +46,33 @@ class AsyncTest {
|
||||
|
||||
var afterLog = ""
|
||||
|
||||
var expectedAfterLog = ""
|
||||
|
||||
@BeforeTest
|
||||
fun before() {
|
||||
log = ""
|
||||
afterLog = ""
|
||||
expectedAfterLog = ""
|
||||
}
|
||||
|
||||
// Until bootstrap update
|
||||
@AfterTest
|
||||
fun after() {
|
||||
assertEquals(afterLog, "after")
|
||||
assertEquals(afterLog, expectedAfterLog)
|
||||
}
|
||||
|
||||
fun promise(v: Int) = Promise<Int> { resolve, reject ->
|
||||
fun promise(v: Int, after: String = "") = Promise<Int> { resolve, reject ->
|
||||
log += "a"
|
||||
js("setTimeout")({ log += "c"; afterLog += "after"; resolve(v) }, 100)
|
||||
js("setTimeout")({ log += "c"; afterLog += after; resolve(v) }, 100)
|
||||
log += "b"
|
||||
}.also {
|
||||
expectedAfterLog += after
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkAsyncOrder(): Promise<Unit> {
|
||||
log += 1
|
||||
|
||||
val p1 = promise(10)
|
||||
val p1 = promise(10, "after")
|
||||
|
||||
log += 2
|
||||
|
||||
@@ -80,9 +85,18 @@ class AsyncTest {
|
||||
return p2
|
||||
}
|
||||
|
||||
@Test
|
||||
fun checkCustomPromise(): CustomPromise {
|
||||
// return promise(10, "afterCustom") as CustomPromise
|
||||
return promise(10, "") as CustomPromise
|
||||
}
|
||||
|
||||
@Test
|
||||
fun asyncPassing() = promise(10).then { assertEquals(10, it) }
|
||||
|
||||
@Test
|
||||
fun asyncFailing() = promise(20).then { assertEquals(10, it) }
|
||||
}
|
||||
}
|
||||
|
||||
@JsName("Promise")
|
||||
external class CustomPromise {}
|
||||
Reference in New Issue
Block a user