Skip to content

Commit

Permalink
fix: refactor tests to await the promise to fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oscarleonnogales committed Oct 30, 2023
1 parent 384a0b4 commit 25d4434
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
40 changes: 24 additions & 16 deletions spec/functional/popup-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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");
});
});
});
15 changes: 11 additions & 4 deletions spec/functional/reply-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
});
});
});
18 changes: 13 additions & 5 deletions spec/functional/target-frames.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 25d4434

Please sign in to comment.