-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
error_test.go
38 lines (32 loc) · 800 Bytes
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//go:build js && wasm
package safejs
import (
"syscall/js"
"testing"
"github.com/hack-pad/safejs/internal/assert"
)
func TestError(t *testing.T) {
t.Parallel()
t.Run("valid error", func(t *testing.T) {
t.Parallel()
jsErr := js.Error{
Value: js.ValueOf(map[string]any{
"message": "foo",
}),
}
const expectedErr = "JavaScript error: foo"
if !assert.EqualError(t, jsErr, expectedErr) { // quickly verify js.Error was created correctly
return
}
err := Error{
err: jsErr,
}
assert.EqualError(t, err, expectedErr)
})
t.Run("invalid error", func(t *testing.T) {
t.Parallel()
jsErr := js.Error{Value: js.Undefined()}
err := Error{err: jsErr}
assert.EqualError(t, err, "failed generating error message: syscall/js: call of Value.Get on undefined")
})
}