Skip to content

Commit 89e8ce4

Browse files
Updated the internalize array test to use JS
1 parent 1da20ac commit 89e8ce4

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tests/js_test.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -869,24 +869,28 @@ func TestInternalizeSlice(t *testing.T) {
869869
}
870870

871871
func TestInternalizeArray(t *testing.T) {
872+
fn := js.Global.Call("eval", "(function(b, v) { b.V = v; })")
873+
872874
tests := []struct {
873875
name string
874-
init [3]int
876+
init any
875877
want string
876878
}{
879+
{
880+
name: `null array`,
881+
init: nil,
882+
want: `[3]int{0, 0, 0}`,
883+
},
877884
{
878885
name: `zeros array`,
879886
init: [3]int{},
880887
want: `[3]int{0, 0, 0}`,
881888
},
882-
// TODO(grantnelson-wf): The following test doesn't pass because
883-
// the assignment of an externalized array doesn't work when this was written,
884-
// see https://github.com/gopherjs/gopherjs/issues/1302
885-
//{
886-
// name: `non-zero array`,
887-
// init: [3]int{42, 53, 64},
888-
// want: `[3]int{42, 53, 64}`,
889-
//},
889+
{
890+
name: `non-zero array`,
891+
init: [3]int{42, 53, 64},
892+
want: `[3]int{42, 53, 64}`,
893+
},
890894
}
891895

892896
for _, tt := range tests {
@@ -895,7 +899,11 @@ func TestInternalizeArray(t *testing.T) {
895899
*js.Object
896900
V [3]int `js:"V"` // V is externalized
897901
}{Object: js.Global.Get("Object").New()}
898-
b.V = tt.init
902+
903+
// Assign the array to b.V using JS because of GopherJS
904+
// assignment of externalized array's issue,
905+
// see https://github.com/gopherjs/gopherjs/issues/1302
906+
fn.Invoke(b, tt.init)
899907

900908
result := fmt.Sprintf(`%#v`, b.V) // internalize b.V
901909
if result != tt.want {

0 commit comments

Comments
 (0)