From 25d4434218558772c523a92d44cacc17e1a6ea76 Mon Sep 17 00:00:00 2001 From: Oscar Leon Date: Mon, 30 Oct 2023 17:10:40 -0600 Subject: [PATCH] fix: refactor tests to await the promise to fix failing tests --- spec/functional/popup-spec.js | 40 +++++++++++++++++++------------- spec/functional/reply-spec.js | 15 ++++++++---- spec/functional/target-frames.js | 18 ++++++++++---- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/spec/functional/popup-spec.js b/spec/functional/popup-spec.js index 7a5709a..00fd90d 100644 --- a/spec/functional/popup-spec.js +++ b/spec/functional/popup-spec.js @@ -35,10 +35,12 @@ describe("Popup Events", () => { timeout: 1000, } ); - const actual = $("p").getText(); - - expect($$("p").length).toBe(1); - expect(actual).toBe(expected); + $("p") + .getText() + .then((actual) => { + expect($$("p").length).toBe(1); + expect(actual).toBe(expected); + }); }); it("should be able to send events to opener frames", () => { @@ -71,10 +73,12 @@ describe("Popup Events", () => { timeout: 1000, } ); - const actual = $("p").getText(); - - expect($$("p").length).toBe(1); - expect(actual).toContain(expected); + $("p") + .getText() + .then((actual) => { + expect($$("p").length).toBe(1); + expect(actual).toContain(expected); + }); }); it("should not double-receive events in popups", () => { @@ -107,10 +111,12 @@ describe("Popup Events", () => { timeout: 1000, } ); - const actual = $("p").getText(); - - expect($$("p").length).toBe(1); - expect(actual).not.toContain("FAILURE"); + $("p") + .getText() + .then((actual) => { + expect($$("p").length).toBe(1); + expect(actual).not.toContain("FAILURE"); + }); }); it("should be able to receive messages from opener window", () => { @@ -141,9 +147,11 @@ describe("Popup Events", () => { timeout: 1000, } ); - const actual = $("p").getText(); - - expect($$("p").length).toBe(1); - expect(actual).not.toContain("FAILURE"); + $("p") + .getText() + .then((actual) => { + expect($$("p").length).toBe(1); + expect(actual).not.toContain("FAILURE"); + }); }); }); diff --git a/spec/functional/reply-spec.js b/spec/functional/reply-spec.js index 86d7969..9192b4e 100644 --- a/spec/functional/reply-spec.js +++ b/spec/functional/reply-spec.js @@ -41,9 +41,16 @@ describe("Reply Events", () => { browser.switchToFrame(2); const frame3ReceivedQuestion = $("p").getText(); - expect(indexReceived).toBe(0); - expect(frame1Received).toBe(0); - expect(frame2Received).toBe(0); - expect(frame3ReceivedQuestion).toBe("are you there?"); + Promise.all([ + indexReceived, + frame1Received, + frame2Received, + frame3ReceivedQuestion, + ]).then(() => { + expect(indexReceived).toBe(0); + expect(frame1Received).toBe(0); + expect(frame2Received).toBe(0); + expect(frame3ReceivedQuestion).toBe("are you there?"); + }); }); }); diff --git a/spec/functional/target-frames.js b/spec/functional/target-frames.js index 8299b07..891e223 100644 --- a/spec/functional/target-frames.js +++ b/spec/functional/target-frames.js @@ -38,10 +38,18 @@ describe("targetFrames Events", () => { browser.switchToFrame(2); const frame3ReceivedQuestion = $$("p").length; - expect(indexReceived).toBe(1); - expect(innerframe1Received).toBe(0); - expect(frame1Received).toBe(0); - expect(frame2Received).toBe(0); - expect(frame3ReceivedQuestion).toBe(0); + Promise.all([ + indexReceived, + innerframe1Received, + frame1Received, + frame2Received, + frame3ReceivedQuestion, + ]).then(() => { + expect(indexReceived).toBe(1); + expect(innerframe1Received).toBe(0); + expect(frame1Received).toBe(0); + expect(frame2Received).toBe(0); + expect(frame3ReceivedQuestion).toBe(0); + }); }); });