is there something wrong with the following test (...
# javascript
l
is there something wrong with the following test (on kotlin/js)?
Copy code
@Test fun `on zero throws`() {
    assertFailsWith<ArithmeticException> {
      1 / 0
    }
  }
it fails with the following message “AssertionError: Expected an exception of class ArithmeticException to be thrown, but was completed successfully.”
e
JS doesn't have integer division; it only has floating-point division returning NaN which Kotlin coerces back to an int (resulting in 0)
if you divided Long / Long you'd get an error because that division is implemented in Kotlin, not JS
l
interesting, thanks for answering. I wonder now how can I have this test (or a similar that should throw
ArithmeticException
) in a commonTest that is run on all different targets? it naturally succeeds on jvm and ios, but not on js
e
1L / 0L
throws on K/JS, but not the same exception. in the future, stdlib will also add a cross-platform BigInteger type, but it will leverage JS BigInt and thus also throw native exception. I don't think this is something you can do, cross-platform.
l
that makes sense.. I guess i have no other alternative than to disable this test?! or is there a way to disable it only for js?
e
I haven't tried this out but perhaps something like
Copy code
@OptionalAnnotation
@Target([AnnotationTarget.CLASS, AnnotationTarget.FUNCTION])
expect annotation class JsIgnore
and then only in JS source set
Copy code
actual typealias JsIgnore = kotlin.test.Ignore
would work
🔝 1