func TestClose(t *testing.T) {
	var closeCalled bool
	close := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		closeCalled = true
		return nil
	})
	tests := []struct {
		webSocket          js.Value
		wantCloseWebSocket bool
	}{
		{},
		{
			webSocket: js.ValueOf(map[string]interface{}{
				"readyState": 1,
				"close":      close,
			}),
			wantCloseWebSocket: true,
		},
	}
	for i, test := range tests {
		closeCalled = false
		leaveCalled := false
		s := Socket{
			webSocket: test.webSocket,
			game: &mockGame{
				LeaveFunc: func() {
					leaveCalled = true
				},
			},
			dom: &mockDOM{
				SetCheckedFunc: func(query string, checked bool) {
					// NOOP
				},
			},
		}
		s.Close()
		if !leaveCalled {
			t.Errorf("Test %v: wanted game to be left", i)
		}
		if want, got := test.wantCloseWebSocket, closeCalled; want != got {
			t.Errorf("Test %v: wanted web socket to be closed: %v, got %v", i, want, got)
		}
	}
	close.Release()
}
// TestClose checks the closing behavior for different isOpen states
TestClose checks the closing behavior for different isOpen states
// TestClose checks the closing behavior for different isOpen states
func TestClose(t *testing.T) {
	var closeCalled bool
	close := js.FuncOf(func(this js.Value, args []js.Value) interface{} {
		closeCalled = true
		return nil
	})
	tests := []struct {
		webSocket          js.Value
		wantCloseWebSocket bool
	}{
		{},
		{
			webSocket: js.ValueOf(map[string]interface{}{
				"readyState": 1,
				"close":      close,
			}),
			wantCloseWebSocket: true,
		},
	}
	for i, test := range tests {
		closeCalled = false
		leaveCalled := false
		s := Socket{
			webSocket: test.webSocket,
			game: &mockGame{
				LeaveFunc: func() {
					leaveCalled = true
				},
			},
			dom: &mockDOM{
				SetCheckedFunc: func(query string, checked bool) {
				},
			},
		}
		s.Close()
		if !leaveCalled {
			t.Errorf("Test %v: wanted game to be left", i)
		}
		if want, got := test.wantCloseWebSocket, closeCalled; want != got {
			t.Errorf("Test %v: wanted web socket to be closed: %v, got %v", i, want, got)
		}
	}
	close.Release()
}
func TestClose ( t * testing . T ) { var closeCalled bool close := js . FuncOf ( func ( this js . Value , args [ ] js . Value ) interface { } { closeCalled = true return nil } ) tests := [ ] struct { webSocket js . Value wantCloseWebSocket bool } { { } , { webSocket : js . ValueOf ( map [ string ] interface { } { " " : 1 , " " : close , } ) , wantCloseWebSocket : true , } , } for i , test := range tests { closeCalled = false leaveCalled := false s := Socket { webSocket : test . webSocket , game : & mockGame { LeaveFunc : func ( ) { leaveCalled = true } , } , dom : & mockDOM { SetCheckedFunc : func ( query string , checked bool ) { } , } , } s . Close ( ) if ! leaveCalled { t . Errorf ( " " , i ) } if want , got := test . wantCloseWebSocket , closeCalled ; want != got { t . Errorf ( " " , i , want , got ) } } close . Release ( ) }
TestClose checks the closing behavior for different isOpen states
TestClose checks the closing behavior for different isOpen states
// NOOP