Repository navigation
javascript window object not available in test #66
|
Hi, I'm trying to make a test suite for Tauri SQL plugin. Currently using mill 0.12.9 and following is my build.sc |
Replies: 1 comment 1 reply
|
What’s happening here is that your tests are being run under a plain JS environment (via Node through Scala.js), but the Tauri SQL plugin expects to be running inside a Tauri runtime where window.TAURI_INTERNALS is defined. ReferenceError: window is not defined because Node doesn’t have a window object. you can try these
import scala.scalajs.js @js.native // In your test bootstrap That way, window.TAURI_INTERNALS.invoke(...) exists during tests and won’t crash.
Instead of Node, you can run Scala.js tests under a headless browser (like jsdom). object test extends ScalaJSTests with ScalaJSRollupModule.Test with TestModule.Weaver {
If your goal is to actually call the real @tauri-apps/plugin-sql inside Tauri, you’ll need to run tests inside a Tauri app (not via Scala.js test runner). In that case, unit tests should mock things (option 1), and you do true integration testing separately in Tauri. |
What’s happening here is that your tests are being run under a plain JS environment (via Node through Scala.js), but the Tauri SQL plugin expects to be running inside a Tauri runtime where window.TAURI_INTERNALS is defined.
ReferenceError: window is not defined because Node doesn’t have a window object.
you can try these
if you only need to exercise your own Scala.js code (not the actual Tauri runtime), you can provide a fake window during testing:
import scala.scalajs.js
import scala.scalajs.js.annotation._
@js.native
@JSGlobalScope
object Globals extends js.Object {
var window: js.Dynamic = js.native
}
// In your test bootstrap
Globals.window = js.Dynamic.literal(
…