Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 60ed06f

Browse files
author
Ivan Mirić
committed
Fix linter issues
1 parent b0a6a02 commit 60ed06f

File tree

2 files changed

+33
-41
lines changed

2 files changed

+33
-41
lines changed

tests/element_handle_test.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
_ "embed"
66
"fmt"
77
"image/png"
8-
"reflect"
98
"testing"
109

1110
"github.com/dop251/goja"
@@ -19,6 +18,7 @@ import (
1918
//go:embed static/mouse_helper.js
2019
var mouseHelperScriptSource string
2120

21+
//nolint:gochecknoglobals
2222
var htmlInputButton = fmt.Sprintf(`
2323
<!DOCTYPE html>
2424
<html>
@@ -79,7 +79,9 @@ func TestElementHandleBoundingBoxSVG(t *testing.T) {
7979
}`
8080
var r api.Rect
8181
webBbox := p.Evaluate(tb.rt.ToValue(pageFn), tb.rt.ToValue(element))
82-
_ = tb.rt.ExportTo(webBbox.(goja.Value), &r)
82+
wb, _ := webBbox.(goja.Value)
83+
err := tb.rt.ExportTo(wb, &r)
84+
require.NoError(t, err)
8385

8486
require.EqualValues(t, bbox, &r)
8587
}
@@ -94,16 +96,15 @@ func TestElementHandleClick(t *testing.T) {
9496
button.Click(tb.rt.ToValue(struct {
9597
NoWaitAfter bool `js:"noWaitAfter"`
9698
}{
97-
NoWaitAfter: true, // FIX: this is just a workaround because navigation is never triggered and we'd be waiting for it to happen otherwise!
99+
// FIX: this is just a workaround because navigation is never triggered
100+
// and we'd be waiting for it to happen otherwise!
101+
NoWaitAfter: true,
98102
}))
99103

100-
result := p.Evaluate(tb.rt.ToValue("() => window['result']")).(goja.Value)
101-
switch result.ExportType().Kind() {
102-
case reflect.String:
103-
assert.Equal(t, result.String(), "Clicked", "expected button to be clicked, but got %q", result.String())
104-
default:
105-
t.Fail()
106-
}
104+
result := p.Evaluate(tb.rt.ToValue("() => window['result']"))
105+
res, ok := result.(goja.Value)
106+
require.True(t, ok)
107+
assert.Equal(t, res.String(), "Clicked")
107108
}
108109

109110
func TestElementHandleClickWithNodeRemoved(t *testing.T) {
@@ -119,16 +120,15 @@ func TestElementHandleClickWithNodeRemoved(t *testing.T) {
119120
button.Click(tb.rt.ToValue(struct {
120121
NoWaitAfter bool `js:"noWaitAfter"`
121122
}{
122-
NoWaitAfter: true, // FIX: this is just a workaround because navigation is never triggered and we'd be waiting for it to happen otherwise!
123+
// FIX: this is just a workaround because navigation is never triggered
124+
// and we'd be waiting for it to happen otherwise!
125+
NoWaitAfter: true,
123126
}))
124127

125-
result := p.Evaluate(tb.rt.ToValue("() => window['result']")).(goja.Value)
126-
switch result.ExportType().Kind() {
127-
case reflect.String:
128-
assert.Equal(t, result.String(), "Clicked", "expected button to be clicked, but got %q", result.String())
129-
default:
130-
t.Fail()
131-
}
128+
result := p.Evaluate(tb.rt.ToValue("() => window['result']"))
129+
res, ok := result.(goja.Value)
130+
require.True(t, ok)
131+
assert.Equal(t, res.String(), "Clicked")
132132
}
133133

134134
func TestElementHandleClickWithDetachedNode(t *testing.T) {
@@ -147,7 +147,9 @@ func TestElementHandleClickWithDetachedNode(t *testing.T) {
147147
panicTestFn := func() {
148148
defer func() {
149149
if err := recover(); err != nil {
150-
errorMsg = err.(*goja.Object).String()
150+
errMsg, ok := err.(*goja.Object)
151+
require.True(t, ok)
152+
errorMsg = errMsg.String()
151153
}
152154
}()
153155
button.Click(tb.rt.ToValue(struct {

tests/page_test.go

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"errors"
2929
"fmt"
3030
"image/png"
31-
"reflect"
3231
"testing"
3332

3433
"github.com/dop251/goja"
@@ -52,29 +51,20 @@ func TestPageEmulateMedia(t *testing.T) {
5251
ReducedMotion: "reduce",
5352
}))
5453

55-
result := p.Evaluate(tb.rt.ToValue("() => matchMedia('print').matches")).(goja.Value)
56-
switch result.ExportType().Kind() {
57-
case reflect.Bool:
58-
assert.True(t, result.ToBoolean(), "expected media 'print'")
59-
default:
60-
t.Fail()
61-
}
54+
result := p.Evaluate(tb.rt.ToValue("() => matchMedia('print').matches"))
55+
res, ok := result.(goja.Value)
56+
require.True(t, ok)
57+
assert.True(t, res.ToBoolean(), "expected media 'print'")
6258

63-
result = p.Evaluate(tb.rt.ToValue("() => matchMedia('(prefers-color-scheme: dark)').matches")).(goja.Value)
64-
switch result.ExportType().Kind() {
65-
case reflect.Bool:
66-
assert.True(t, result.ToBoolean(), "expected color scheme 'dark'")
67-
default:
68-
t.Fail()
69-
}
59+
result = p.Evaluate(tb.rt.ToValue("() => matchMedia('(prefers-color-scheme: dark)').matches"))
60+
res, ok = result.(goja.Value)
61+
require.True(t, ok)
62+
assert.True(t, res.ToBoolean(), "expected color scheme 'dark'")
7063

71-
result = p.Evaluate(tb.rt.ToValue("() => matchMedia('(prefers-reduced-motion: reduce)').matches")).(goja.Value)
72-
switch result.ExportType().Kind() {
73-
case reflect.Bool:
74-
assert.True(t, result.ToBoolean(), "expected reduced motion setting to be 'reduce'")
75-
default:
76-
t.Fail()
77-
}
64+
result = p.Evaluate(tb.rt.ToValue("() => matchMedia('(prefers-reduced-motion: reduce)').matches"))
65+
res, ok = result.(goja.Value)
66+
require.True(t, ok)
67+
assert.True(t, res.ToBoolean(), "expected reduced motion setting to be 'reduce'")
7868
}
7969

8070
func TestPageEvaluate(t *testing.T) {

0 commit comments

Comments
 (0)