Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Commit

Permalink
Refactor test so that we're checking the promise
Browse files Browse the repository at this point in the history
We just want to make sure that the promises actually complete and are
fulfilled before we end the test, so we're checking the state of the
promise in `tb.await` as well as after `tb.await`. There's a chance
that the action has already completed before the first state check, but
the resolve/rejection only occurs `tb.await` returns.

Resolves: #467 (comment)
  • Loading branch information
ankur22 committed Aug 9, 2022
1 parent e118dc3 commit 17f107f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tests/frame_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ func TestWaitForFrameNavigationWithinDocument(t *testing.T) {
Timeout: timeout, // interpreted as ms
}))
cPromise = p.Click(tc.selector, nil)

assert.Equal(t, goja.PromiseStatePending, wfnPromise.State())
assert.Equal(t, goja.PromiseStatePending, cPromise.State())

return nil
})
if err != nil {
Expand Down Expand Up @@ -112,11 +116,21 @@ func TestWaitForFrameNavigation(t *testing.T) {
WaitUntil: common.LifecycleEventNetworkIdle,
Timeout: common.DefaultTimeout,
})))

var wfnPromise, cPromise *goja.Promise
err := tb.await(func() error {
_ = p.Click(`a`, nil)
p.WaitForNavigation(nil)
wfnPromise = p.WaitForNavigation(nil)
cPromise = p.Click(`a`, nil)

assert.Equal(t, goja.PromiseStatePending, wfnPromise.State())
assert.Equal(t, goja.PromiseStatePending, cPromise.State())

return nil
})

assert.Equal(t, goja.PromiseStateFulfilled, wfnPromise.State())
assert.Equal(t, goja.PromiseStateFulfilled, cPromise.State())

require.NoError(t, err)
require.Equal(t, p.Title(), "Second page")
}

0 comments on commit 17f107f

Please sign in to comment.