go/wasm how to test browser APIs

82 views
Skip to first unread message

mi...@ubo.ro

unread,
Apr 8, 2022, 7:31:59 AM4/8/22
to golang-nuts
I'm trying to unitest a browser wasm/js application but it seems that the browser objects are missing. I assume that the testing package is using a "serverside" node API so I wonder how can I make go test use a real browser to run the tests. The test below fails

func TestTransform(t *testing.T) {
  doc := js.Global().Get("document")
  if !doc.Truthy() {
   t.Fatalf("window.document not available?? wrong environment")
  }


// $ GOOS=js GOARCH=wasm go test

Corin Lawson

unread,
Apr 9, 2022, 5:24:26 PM4/9/22
to golang-nuts
I suppose you need to load and run the tests in browser... this might help: https://github.com/agnivade/wasmbrowsertest
Reply all
Reply to author
Forward
0 new messages