Skip to content

Commit 36c87e1

Browse files
committed
test: Extract AssertFixture
1 parent 2a5a843 commit 36c87e1

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

html/html_form_element_submit_test.go

+11-37
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,37 @@ import (
1111
"github.com/gost-dom/browser/html"
1212
"github.com/gost-dom/browser/internal/gosthttp"
1313
"github.com/gost-dom/browser/internal/testing/eventtest"
14+
"github.com/gost-dom/browser/internal/testing/fixtures"
1415
. "github.com/gost-dom/browser/internal/testing/gomega-matchers"
1516
"github.com/gost-dom/browser/internal/testing/htmltest"
1617
. "github.com/gost-dom/browser/testing/gomega-matchers"
1718
"github.com/gost-dom/fixture"
18-
"github.com/onsi/gomega"
19-
"github.com/onsi/gomega/types"
20-
"github.com/stretchr/testify/assert"
2119
)
2220

23-
type AssertFixture struct {
24-
fixture.Fixture
25-
assert *assert.Assertions
26-
gomega gomega.Gomega
27-
}
28-
29-
func (f *AssertFixture) Assert() *assert.Assertions {
30-
if f.assert == nil {
31-
f.assert = assert.New(f.TB)
32-
}
33-
return f.assert
34-
}
35-
36-
func (f *AssertFixture) Expect(actual interface{}, extra ...interface{}) types.Assertion {
37-
if f.gomega == nil {
38-
f.gomega = gomega.NewWithT(f.TB)
39-
}
40-
return f.gomega.Expect(actual, extra...)
41-
}
42-
43-
type HTTPHandlerFixture struct {
44-
*http.ServeMux
45-
}
21+
type HTTPHandlerFixture struct{ *http.ServeMux }
4622

4723
func (f *HTTPHandlerFixture) Setup() {
48-
f.ServeMux = http.NewServeMux()
24+
if f.ServeMux == nil {
25+
f.ServeMux = http.NewServeMux()
26+
}
4927
}
5028

5129
type WindowFixture struct {
52-
AssertFixture
53-
BaseLocation string
30+
fixtures.AssertFixture
5431
*HTTPHandlerFixture
55-
Window htmltest.WindowHelper
5632

57-
form html.HTMLFormElement
33+
Window htmltest.WindowHelper
34+
BaseLocation string
5835
}
5936

6037
func (f *WindowFixture) Setup() {
6138
if f.Window.Window != nil {
6239
return
6340
}
64-
opts := html.WindowOptions{
41+
win := html.NewWindow(html.WindowOptions{
6542
BaseLocation: f.BaseLocation,
6643
HttpClient: gosthttp.NewHttpClientFromHandler(f.HTTPHandlerFixture),
67-
}
68-
win := html.NewWindow(opts)
44+
})
6945
f.Window = htmltest.NewWindowHelper(f.TB, win)
7046

7147
f.Helper()
@@ -129,9 +105,7 @@ type HTMLFormFixture struct {
129105
}
130106

131107
func TestSubmitForm(t *testing.T) {
132-
w, setup := fixture.Init(t, &struct {
133-
DefaultWindowFixture
134-
}{})
108+
w, setup := fixture.Init(t, &DefaultWindowFixture{})
135109
w.BaseLocation = "http://example.com/forms/example-form.html?original-query=original-value"
136110
setup.Setup()
137111

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package fixtures
2+
3+
import (
4+
"github.com/gost-dom/fixture"
5+
"github.com/onsi/gomega"
6+
"github.com/onsi/gomega/types"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
type AssertFixture struct {
11+
fixture.Fixture
12+
assert *assert.Assertions
13+
gomega gomega.Gomega
14+
}
15+
16+
func (f *AssertFixture) Assert() *assert.Assertions {
17+
if f.assert == nil {
18+
f.assert = assert.New(f.TB)
19+
}
20+
return f.assert
21+
}
22+
23+
func (f *AssertFixture) Expect(actual interface{}, extra ...interface{}) types.Assertion {
24+
if f.gomega == nil {
25+
f.gomega = gomega.NewWithT(f.TB)
26+
}
27+
return f.gomega.Expect(actual, extra...)
28+
}

0 commit comments

Comments
 (0)