From 17f107f9ea3cf3cf8c5400a131e8b0ee9c7cf2cd Mon Sep 17 00:00:00 2001 From: ankur22 Date: Tue, 9 Aug 2022 11:26:44 +0100 Subject: [PATCH] Refactor test so that we're checking the promise 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: https://github.com/grafana/xk6-browser/pull/467#discussion_r932044728 --- tests/frame_manager_test.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/frame_manager_test.go b/tests/frame_manager_test.go index 83ad5711a..af3be737c 100644 --- a/tests/frame_manager_test.go +++ b/tests/frame_manager_test.go @@ -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 { @@ -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") }