5
5
_ "embed"
6
6
"fmt"
7
7
"image/png"
8
- "reflect"
9
8
"testing"
10
9
11
10
"github.com/dop251/goja"
@@ -19,6 +18,7 @@ import (
19
18
//go:embed static/mouse_helper.js
20
19
var mouseHelperScriptSource string
21
20
21
+ //nolint:gochecknoglobals
22
22
var htmlInputButton = fmt .Sprintf (`
23
23
<!DOCTYPE html>
24
24
<html>
@@ -79,7 +79,9 @@ func TestElementHandleBoundingBoxSVG(t *testing.T) {
79
79
}`
80
80
var r api.Rect
81
81
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 )
83
85
84
86
require .EqualValues (t , bbox , & r )
85
87
}
@@ -94,16 +96,15 @@ func TestElementHandleClick(t *testing.T) {
94
96
button .Click (tb .rt .ToValue (struct {
95
97
NoWaitAfter bool `js:"noWaitAfter"`
96
98
}{
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 ,
98
102
}))
99
103
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" )
107
108
}
108
109
109
110
func TestElementHandleClickWithNodeRemoved (t * testing.T ) {
@@ -119,16 +120,15 @@ func TestElementHandleClickWithNodeRemoved(t *testing.T) {
119
120
button .Click (tb .rt .ToValue (struct {
120
121
NoWaitAfter bool `js:"noWaitAfter"`
121
122
}{
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 ,
123
126
}))
124
127
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" )
132
132
}
133
133
134
134
func TestElementHandleClickWithDetachedNode (t * testing.T ) {
@@ -147,7 +147,9 @@ func TestElementHandleClickWithDetachedNode(t *testing.T) {
147
147
panicTestFn := func () {
148
148
defer func () {
149
149
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 ()
151
153
}
152
154
}()
153
155
button .Click (tb .rt .ToValue (struct {
0 commit comments