Skip to content

Commit

Permalink
Add TestBrowserContextDefaultOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 7, 2024
1 parent e59169b commit d72e163
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions browser/browser_context_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/grafana/xk6-browser/common"
"github.com/grafana/xk6-browser/k6ext/k6test"
Expand Down Expand Up @@ -40,3 +41,24 @@ func TestBrowserContextSetGeolocation(t *testing.T) {
assert.Equal(t, 2.0, opts.Geolocation.Longitude)
assert.Equal(t, 3.0, opts.Geolocation.Accuracy)
}

func TestBrowserContextDefaultOptions(t *testing.T) {
vu := k6test.NewVU(t)

defaults := common.NewBrowserContextOptions()

// gets the default options by default
opts, err := parseBrowserContextOptions(vu.Runtime(), nil)
require.NoError(t, err)
assert.Equal(t, defaults, opts)

// merges with the default options
opts, err = parseBrowserContextOptions(vu.Runtime(), vu.ToSobekValue((struct {
DeviceScaleFactor float64 `js:"deviceScaleFactor"` // just to test a different field
}{
DeviceScaleFactor: defaults.DeviceScaleFactor + 1,
})))
require.NoError(t, err)
assert.NotEqual(t, defaults.DeviceScaleFactor, opts.DeviceScaleFactor)
assert.Equal(t, defaults.Locale, opts.Locale) // should remain as default
}

0 comments on commit d72e163

Please sign in to comment.