# How to do WASM Unit tests with function defined in Index.html?

**URL:** <https://discuss.kotlinlang.org/t/how-to-do-wasm-unit-tests-with-function-defined-in-index-html/31063>\
**Category:** Multiplatform\
**Created:** [May 19, 2026, 7:38am UTC](https://discuss.kotlinlang.org/t/how-to-do-wasm-unit-tests-with-function-defined-in-index-html/31063 "2026-05-19T07:38:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![monoseb](https://avatars.discourse-cdn.com/v4/letter/m/919ad9/32.png) [@monoseb](https://discuss.kotlinlang.org/u/monoseb)\
**Post date:** [May 19, 2026, 7:38am UTC](https://discuss.kotlinlang.org/t/how-to-do-wasm-unit-tests-with-function-defined-in-index-html/31063/1 "2026-05-19T07:38:46Z")

</div>

Hello,

I created a simple function in my `index.html` that is called in my `feature.wasm.kt` as an `external` function.

`external fun myFunction(text: String): JSArray<JsString>` in Kotlin

and in `index.html`

```auto
<script>
  function myFunction(text) { doSomething() }
</script>

```

The function works when testing manually in browser. But Unit tests fail with the error:  
`kotlin.js.JsException: myFunction is not defined`

I tried to add Karma in my gradle, and call tests from the `wasmJsBrowserTest` gradle task, but still get the error.

```auto
wasmJs {
    browser {
        testTask {
            useKarma {
                useChromeHeadless()
            }
        }
    }
    binaries.executable()
}

```

I’m trying to piece together how Karma should be configured to include my files, but the only information I found is in the from the KMP/JS page [Run tests in Kotlin/JS | Kotlin Documentation](https://kotlinlang.org/docs/js-running-tests.html) and doesn’t go into much details configuration.
