Mike Kienenberger
03/05/2026, 4:22 PMtanstack-react-router-nodejs-test in kotlin-wrappers.
One thing I noticed is that the examples didn't run for me out of the box using ./gradlew tanstack-react-router:jsBrowserDevelopmentRun
I had to run ./gradlew tanstack-react-router:kotlinNodeJsSetup first before the correct version of node was found. That's probably not going to be obvious to some people. I haven't had to use that in my own react projects, so it's unclear why it was required here.turansky
03/05/2026, 5:03 PMMike Kienenberger
03/06/2026, 12:28 AMMike Kienenberger
03/06/2026, 12:32 AMMike Kienenberger
03/06/2026, 1:14 AMact {}, but I think I got the KW RTL mostly working using render(). Unfortunately. fireEvent() RTL gets runtime errors.
I also tried KW testingLibraryUserEvent but that dies with an error at startup.
The API there is pretty bad, forcing the end-user to pass in js("undefined") to function calls, but it's a start.
Exception during run: Error: Package subpath './dist/esm/setup/index' is not defined by "exports"
in .../kotlin-wrappers/examples/build/js/node_modules/@testing-library/user-event/package.json
imported from .../kotlin-wrappers/examples/build/js/packages/tanstack-react-router-nodejs-test-test/kotlin/tanstack-react-router-nodejs-test-test/example/RouterTest.mjsMike Kienenberger
03/06/2026, 1:15 AMturansky
03/06/2026, 2:47 AMSergei Grishchenko
03/06/2026, 8:58 AMact {}
As far as I understand act is reexported from React as is, recently we also moves act to react package in KW, please, try to use act from that place, if it does not work for you, please, describe what is wrong, we will try to fix the issue
> fireEvent() RTL gets runtime errors
To reproduce it I may use you fork, right?
> Exception during run: Error: Package subpath './dist/esm/setup/index' is not defined by "exports"
hm, interesting, as far as I can see from NPM
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
},
"./dist/cjs/*.js": {
"types": "./dist/types/*.d.ts",
"import": "./dist/esm/*.js",
"default": "./dist/cjs/*.js"
},
"./dist/esm/*.js": {
"types": "./dist/types/*.d.ts",
"default": "./dist/esm/*.js",
"require": "./dist/cjs/*.js"
}
},
so ./dist/esm/setup/index should be matched by ./dist/esm/*.js pattern, maybe K/JS do not generate .js extension in the import statement and that is the problem... we need to investigate it, thank you for the reportMike Kienenberger
03/06/2026, 2:01 PMval indexContainer : web.dom.Element = screen.findByTestId(DataTestId.INDEX_CONTAINER)
- jsmint:
val indexContainer = screen.findByTestId(DataTestId.INDEX_CONTAINER)
* Screen calls require explicit typecasting of returned values
- kotlin-wrappers:
val indexContainer : web.dom.Element = screen.findByTestId(DataTestId.INDEX_CONTAINER)
- jsmint:
val indexContainer = screen.findByTestId(DataTestId.INDEX_CONTAINER)
* fireEvent needs a convenience wrapper
- kotlin-wrappers RTL:
fireEvent[EventType.click]?.invoke(topicsLink, js("undefined"))
- jsmint:
fireEvent.click(topicsLink)
* fireEvent(options=) does not default to js("undefined")
- kotlin-wrappers RTL:
fireEvent[EventType.click]?.invoke(topicsLink, js("undefined"))
- expected:
fireEvent[EventType.click]?.invoke(topicsLink)
* adding kotlinWrappers.testingLibraryReact dependency requires adding npm("@testing-library/react", "VERSION") dependency.
- kotlin-wrappers RTL:
jsTestImplementation(kotlinWrappers.testingLibraryReact)
jsTestImplementation(npm("@testing-library/react", "latest"))
- jsmint (from our production project):
implementation(project.dependencies.enforcedPlatform(libs.jsmints.bom))
implementation(libs.jsmints.react.testing.library)
implementation(libs.jsmints.user.event.testing.library.js)
* userEvent.setup does not default to js("undefined")
- kotlin-wrappers UE:
val user = userEvent.setup(JS_UNDEFINED)
- jsmint:
val user = UserEvent.setup()
* user.click(options=) does not default to js("undefined")
- kotlin-wrappers UE:
user.click(topicsLink, JS_UNDEFINED).await()
- jsmint:
user.click(topicsLink)
* user.click() does not automatically await() the returned promise
- kotlin-wrappers UE:
user.click(topicsLink, JS_UNDEFINED).await()
- jsmint:
user.click(topicsLink)
* jsmint's act {} also awaits() before returning
- PROS:
* jsmint doesn't provide cleanup().
- kotlin-wrappers RTL:
cleanup()
- jsmint:
act { root.unmount() }
container.remove()
* I hadn't used RTL render() before, but it's nice not to have to set up the document and container,
which I have to do with act {}. Maybe jsmint also works this way. I need to do more research.Sergei Grishchenko
03/06/2026, 2:35 PMunsafeCast results of querying if you want to get some specific props
I guess you can use something like this
val indexContainer = screen.findByTestId<Element>(DataTestId.INDEX_CONTAINER)
(Also I noticed this point is mentioned twice, maybe you wanted to report something else by forget to replace the copied point? I don't want to lose feedback 🙂)
> fireEvent needs a convenience wrapper
Will it be actual if primary method of event dispatching is UE?
> fireEvent(options=) does not default to js("undefined")
Got it, unfortunately Kotlin does not support optional params in function types, I will think about how to adapt this API. BTW you can use undefined constant without js block.
> * adding kotlinWrappers.testingLibraryReact dependency requires adding npm("@testing-library/react", "VERSION") dependency
misconfig, I pushed the fix
> userEvent.setup does not default to js("undefined")
Yes, you are right, I will fix it. It know issue.
> user.click(options=) does not default to js("undefined")
The same as previous
> user.click() does not automatically await() the returned promise
The same as previous, UE are on really on early stage of conversion, most promise APIs will be wrapped to suspendsSergei Grishchenko
03/06/2026, 2:39 PMSergei Grishchenko
03/06/2026, 2:44 PMJS_UNDEFINED constant, why you do not use just undefined? Is it because of WASM related staff of something like this?Mike Kienenberger
03/06/2026, 3:00 PMOriginal API from TS library allows to pass type of DOM element that you expect as query result, I guess it might be useful if you want to examine some properties that are specific to some HTML elements (e.g. for input). If I hardcode element type instead of generic you will have to typecast or unsafeCast results of querying if you want to get some specific propsThe only use case we've had for the query result is to either click it, type text into it, or examine attributes of the html element. All of those require that the type be an HTMLElement. Having it return a generic adds boilerplate to every statement. This is how jsmints exposes it:
import org.w3c.dom.HTMLElement
interface ByTestId {
fun getByTestId(text: String): HTMLElement
suspend fun findByTestId(text: String): HTMLElement
fun queryByTestId(text: String): HTMLElement?
fun getAllByTestId(text: String): Array<HTMLElement>
fun queryAllByTestId(text: String): Array<HTMLElement>
suspend fun findAllByTestId(text: String): Array<HTMLElement>
}
Will [fireEvent] be actual if primary method of event dispatching is UE?We never use fireEvent and always use UE, but that's what was available for the example. jsmints made it easier to use fireEvent.
I notices you use some JS_UNDEFINED constant, why you do not use just undefined?I didn't know it existed :) We don't do much with raw javascript from kotlin. Sounds like it won't matter as the final code won't need to specify undefined.
Mike Kienenberger
03/06/2026, 3:05 PMgeneric query resultAlso, without an explicit type, the code doesn't compile:
val indexContainer = screen.findByTestId(DataTestId.INDEX_CONTAINER)
Cannot infer type for type parameter 'T'. Specify it explicitly.Sergei Grishchenko
03/06/2026, 3:07 PMThis is how jsmints exposes it:Yea, I checked that declarations, and unfortunately I am suspicious about type narrowing to
HTMLElement , I guess Element as upper bound of generic allows you also querying SVG elements, I understand that SVG is not so popular but I would not limit users with to narrow solution also, because KW is common library.turansky
03/06/2026, 3:10 PMDataTestId can be inteface with type parameter, which will contain right typeSergei Grishchenko
03/06/2026, 3:10 PMHTMLElementSergei Grishchenko
03/06/2026, 3:12 PMsorry, I dont think that is good solution, because there are other queries, likecan be inteface with type parameter, which will contain right typeDataTestId
findAllByLabelText and it would be uncommon and very local fix just for one type of query.Sergei Grishchenko
03/06/2026, 3:18 PMAlso, without an explicit type, the code doesn't compile:Yea, this is exactly because right now
<T : web.html.HTMLElement/> is declared, an there is not point in code to get exact type for T
but you can write something like
val indexContainer = screen.findByTestId<HTMLElement>(DataTestId.INDEX_CONTAINER)
And code should compileMike Kienenberger
03/06/2026, 3:26 PMval indexContainer = screen.findByTestId<HTMLElement>(DataTestId.INDEX_CONTAINER)
and
val indexContainer : HTMLElement = screen.findByTestId(DataTestId.INDEX_CONTAINER)
It seems unnecessary to always specify the same generic type and never a different one. jsmints non-generic functions are nicer. That's not a show-stopper, but it's an API inconvenience. We could replace all of the query statements with our own extension functions to hide this, but that'd likely be more inconvenient.
Who's the target audience and what do they need for an api?
So far, all of us kotlin RTL users are using jsmints API and no one has asked for a different signature.
Again, it wouldn't prevent me from switching from jsmints to KW, but it's not ideal.
Also, after more investigation, it looks like I should have been using render() instead of act {} all along. We'll need to make that change in our production project.Mike Kienenberger
03/06/2026, 3:43 PMval componentTopicLink = within(screen.findByTestId<HTMLElement>(DataTestId.TOPICS_CONTAINER)).findByTestId<HTMLElement>(DataTestId.TOPIC_LINK_COMPONENTS)
I'm not sure what that is intended to look like in KW.
The above code generates:
Cannot infer type for type parameter 'R'. Specify it explicitly.
Cannot infer type for type parameter 'T'. Specify it explicitly.
<html>Unresolved reference. None of the following candidates is applicable because of a receiver type mismatch:<br/>fun <T, R> DeepRecursiveFunction<T, R>.invoke(value: T): R
Unresolved reference 'findByTestId'.Sergei Grishchenko
03/06/2026, 3:50 PM<*> syntax, but it works not everywhere, it would be nice to write screen.findByTestId<*>(DataTestId.INDEX_CONTAINER) and fail to upper bound of generic, but unfortunately it is not possible now, but I see it as good compromise between flexibility and convenience
• Actually Testing library does not provide any guaranties that returned item will have exact type that was passed in <T> param, and it is not good because it leads to unsound code. Maybe it is good reason to remove generics, but for now I don't know what is better: give more generic and unsound API or give more safe but narrow API.Sergei Grishchenko
03/06/2026, 3:53 PMval componentTopicLink = within
Yea, I see, now within has type Any because of TS metaprogramming, I will take a look and try to improve type declarations for it.Mike Kienenberger
03/06/2026, 3:54 PMturansky
03/06/2026, 4:01 PMfindByTestId it can be better for sure.
For start - we can remove generics (it's what we do for some browser declarations).
Kotlin Wrappers meta issue will be best place for non-comfortable API in RTL 😉
cc @Sergei GrishchenkoMike Kienenberger
03/06/2026, 10:17 PMSergei Grishchenko
03/06/2026, 10:46 PMrender() , you still have to run cleanup() after each test, maybe we will provide some API to reduce these boilerplate in the future.Mike Kienenberger
03/07/2026, 12:24 AMI totally forget to warn you, if you useThanks. Yes, I knew that 🙂 and it's in the example test. Using cleanup is so much better than what we were having to do before, with having to remove container and unmount root. I copied the cleanup.kt file into our production project to take advantage of it since jsmints didn't provide it. All of our production testing code inherits from a superclass and hides all of that boilerplate., you still have to runrender()after each test, maybe we will provide some API to reduce these boilerplate in the future.cleanup()
Sergei Grishchenko
03/08/2026, 4:48 PMScreen API, because they are unsound.
> fireEvent needs a convenience wrapper
> ...
> fireEvent(options=) does not default to js("undefined")
I decided not to do anything with this API for now, because as far as I understand, primary approach for event dispatching is UE.
> val componentTopicLink = within(screen.findByTestId<HTMLElement>(DataTestId.TOPICS_CONTAINER)).findByTestId<HTMLElement>(DataTestId.TOPIC_LINK_COMPONENTS)
I tried to improve types for within helper. I hope problem should be fixed.
> userEvent.setup does not default to js("undefined")
> ...
> user.click(options=) does not default to js("undefined")
> ...
> user.click() does not automatically await() the returned promise
I tried to rework and improve UE API, with latest changes these problems should gone, if not - please, reach us.
> Exception during run: Error: Package subpath './dist/esm/setup/index' is not defined by "exports"
I found the problem with @JsModule in generated declarations. I fixed generation and added some primitive tests to check that entities from UE are available in runtime.Sergei Grishchenko
03/08/2026, 4:51 PMMike Kienenberger
03/09/2026, 4:28 PMMike Kienenberger
03/10/2026, 4:03 PMglobalThis.IS_REACT_ACT_ENVIRONMENT = true; but KW does not.
I had to add this to build.gradle.kts
compilations.named("test") {
packageJson { customField("mocha", mapOf("require" to arrayOf(
"../../../../tools/mocha-support/set-react-act-env.js",
[...]
)))}
}
and
// tools/mocha-support/set-react-act-env.js
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
I'm guessing there's a better way to do it, but that's what I came up with.Sergei Grishchenko
03/10/2026, 4:06 PMglobalThis["IS_REACT_ACT_ENVIRONMENT"] = true
in @BeforeTest method, it might helpMike Kienenberger
03/10/2026, 4:06 PMpackage com.zegreatrob.wrapper.testinglibrary.react
fun main() {
js("global.IS_REACT_ACT_ENVIRONMENT=true")
}
And like this for UE:
jsTest >> Main.kt
package com.zegreatrob.wrapper.testinglibrary.userevent
fun main() {
js("global.IS_REACT_ACT_ENVIRONMENT=true")
js("global.IS_JSDOM=true")
}Sergei Grishchenko
03/10/2026, 4:08 PMmain function as global setup for tests.Sergei Grishchenko
03/10/2026, 4:09 PMglobalThis["IS_REACT_ACT_ENVIRONMENT"] = true is Kotlin code, KW provides global val for globalThisMike Kienenberger
03/10/2026, 4:09 PMBTW,Yes, testing that now.is Kotlin code, KW provides global val forglobalThis["IS_REACT_ACT_ENVIRONMENT"] = trueglobalThis
Mike Kienenberger
03/10/2026, 4:13 PMglobalThis["IS_REACT_ACT_ENVIRONMENT"] = true
globalThis["IS_JSDOM"] = true
in the before test calls does work, but it does mean that the end-developer has to remember to do so for each test.
Not a big deal in our environment since all of our react tests inherit from a single superclass.
But if we go this route, it'd mean we'd need to add some docs to KW RTL and KW UEturansky
03/10/2026, 4:18 PMrunTest from Coroutines Test?Mike Kienenberger
03/10/2026, 4:20 PMMike Kienenberger
03/10/2026, 4:21 PMturansky
03/10/2026, 4:21 PMrunTest ?Mike Kienenberger
03/10/2026, 4:23 PM// Use dependency injection to inject this test CoroutineScope into your production code instead of MainScope
object JsTestScope : CoroutineScope {
override val coroutineContext =
SupervisorJob() + Dispatchers.Default
}
@Test
fun shouldClickTopicsLinkAndNavigateToTopicsPage(): Promise<Unit> = JsTestScope.promise {
}Mike Kienenberger
03/10/2026, 4:23 PMMike Kienenberger
03/10/2026, 8:06 PMMike Kienenberger
03/10/2026, 8:06 PMMike Kienenberger
03/19/2026, 3:29 PMglobalThis["IS_REACT_ACT_ENVIRONMENT"] = true
This is the expected place it would be set from according to the documentation, rather than requiring end-users to do it.
https://react.dev/reference/react/act#error-the-current-testing-environment-is-not-configured-to-support-act
Note
In testing frameworks like React Testing Library,is already set for you.IS_REACT_ACT_ENVIRONMENT
Mike Kienenberger
03/19/2026, 3:32 PMNODE_ENV=test. I don't think we can consider this a bug so much as two competing design philosophies. Node.js says don't do it. Jest and Vite do it by default.
Maybe I should update the README for the testing example to include this?
* `@tanstack/react-router` requires `NODE_ENV=test` to run in a node/jsdom environment. By default, no `NODE_ENV` mode
is set.
- Work-around: Change `build.gradle.kts` to set `NODE_ENV=test` when running jsNodeTest
- The requirement to set `NODE_ENV=test` is not a bug in the jsNodeTask.
* Requiring the use of `NODE_ENV=test` is considered an anti-pattern by the node.js project.
- <https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production#why-is-node_env-considered-an-antipattern>
* Setting `NODE_ENV=test` is considered standard practice by the vite project.
- <https://vitest.dev/guide/migration.html?utm_source=chatgpt.com#envs>turansky
03/19/2026, 5:04 PMNode.js says don't do it.In that case it's custom plugin/project responsibility
Mike Kienenberger
03/19/2026, 5:05 PMturansky
03/19/2026, 5:06 PMjsdom Gradle plugin 😉turansky
03/19/2026, 5:07 PMSergei Grishchenko
03/19/2026, 5:22 PMact from testing library is tiny wrapper over act from React, now I see that it is not true. I will remove act in react package and move it's declaration to testing library. @turansky does it work for you?Sergei Grishchenko
03/19/2026, 5:32 PMact with correct IS_REACT_ACT_ENVIRONMENT should be available from testing.library.react packageMike Kienenberger
03/19/2026, 8:54 PMIS_REACT_ACT_ENVIRONMENT.Mike Kienenberger
03/19/2026, 8:59 PMturansky
03/20/2026, 12:03 AMThis is probably why jsmints unconditionally set IS_REACT_ACT_ENVIRONMENT.In custom
runTest ?Mike Kienenberger
03/20/2026, 12:09 AMMike Kienenberger
03/20/2026, 12:10 AMLooks like we miss jsdom Gradle plugin 😉
Which will do all this dark magic 😉
turansky
03/20/2026, 12:22 AMrunTest 😉turansky
03/20/2026, 12:23 AMMike Kienenberger
03/20/2026, 1:09 PMturansky
03/20/2026, 1:13 PMact in example, right?Mike Kienenberger
03/20/2026, 1:14 PMturansky
03/20/2026, 1:17 PMdispatchEvent for example)Mike Kienenberger
03/20/2026, 1:27 PMSergei Grishchenko
03/20/2026, 1:33 PMIS_REACT_ACT_ENVIRONMENT is not set
• from Testing Library -> wraps React's act + sets up IS_REACT_ACT_ENVIRONMENT before and after its calling
In the code you provided act is imported from local file
import act, ... from './act-compat'
So I hope that is not bare React's act , it is wrapped one. So I hope if you use RTL render you are in safe and you should not receive any warnings about env. But if you have some problems anyway, please share some test snippet, I can try to debug it.Sergei Grishchenko
03/20/2026, 1:34 PMact safe, I just exported exiting safe version from RTLMike Kienenberger
03/25/2026, 8:18 PMversionCatalogs {
create("kotlinWrappers") {
- val wrappersVersion = "2026.3.13"
+ val wrappersVersion = "2026.3.15"
@Sergei Grishchenko, did you remove react.act?
I don't think that's a good idea. If the end user is not using RTL, they likely need react.act. The end-user is going to have to be knowledgeable enough to determine which import they use.
https://react.dev/reference/react/actMike Kienenberger
03/25/2026, 8:19 PMturansky
03/25/2026, 9:43 PMreact.act is problem for RTL users unfortunately 😞Mike Kienenberger
03/25/2026, 9:44 PMMike Kienenberger
03/25/2026, 9:45 PMMike Kienenberger
03/25/2026, 9:52 PMMike Kienenberger
03/25/2026, 9:53 PMMike Kienenberger
03/25/2026, 9:54 PMMike Kienenberger
03/25/2026, 9:55 PMturansky
03/25/2026, 10:15 PMSergei Grishchenko
03/28/2026, 11:55 AMact was declared in react-dom/test-utils
• approximately around React 19 act was moved to react package and other helpers from react-dom/test-utils were removed
• here and there React docs mention RTL, so I assume the it is de facto standard
• I don't remember how it worked before, but now act from react requires IS_REACT_ACT_ENVIRONMENT to work correctly, I tried to investigate what RTL does to provide correct setup for IS_REACT_ACT_ENVIRONMENT and I found this code, as you can see, this code is not trivial and I don't expect that every end user of React should write this.
After all these facts I consider act from react package as low-level API for testing library authors and RTL one of such library that seems de facto standard. So original act from react may be useful only if some Kotlin enthusiast want to write alternative library for React testing, For now I see it as very low probable scenario, that is why I don't see much sense in declaration of act from react package.
If I am missing something, please, share you thoughts.