From 88dad021fd134693843956162981013b64853be5 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 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tests/frame_manager_test.go b/tests/frame_manager_test.go index 83ad5711a..07b1f8276 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,20 @@ 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 }) require.NoError(t, err) - require.Equal(t, p.Title(), "Second page") + + assert.Equal(t, goja.PromiseStateFulfilled, wfnPromise.State()) + assert.Equal(t, goja.PromiseStateFulfilled, cPromise.State()) + assert.Equal(t, "Second page", p.Title()) }