From 20a42919965c66ea3e8ad99202197c6bda498563 Mon Sep 17 00:00:00 2001 From: Philipp Thiele Date: Tue, 9 May 2023 11:31:15 +0200 Subject: [PATCH] enhance tests for exec using sinon --- .../ui5-js-app/webapp/test/e2e/exec.test.js | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/ui5-js-app/webapp/test/e2e/exec.test.js b/examples/ui5-js-app/webapp/test/e2e/exec.test.js index 3790e159..20924f44 100644 --- a/examples/ui5-js-app/webapp/test/e2e/exec.test.js +++ b/examples/ui5-js-app/webapp/test/e2e/exec.test.js @@ -1,9 +1,21 @@ const Main = require("./pageObjects/Main") const Other = require("./pageObjects/Other") const marky = require("marky") +const sinon = require("sinon") const { wdi5 } = require("wdio-ui5-service") +const Logger = wdi5.getLogger() describe("ui5 eval on control", () => { + const sandbox = sinon.createSandbox() + + beforeEach(() => { + sandbox.spy(Logger, "error") + }) + + afterEach(() => { + sandbox.restore() + }) + before(async () => { await Main.open() }) @@ -13,10 +25,7 @@ describe("ui5 eval on control", () => { expect(title).toEqual("Sample UI5 Application") }) - it("should be able to propagate a browserside error", async () => { - //Log Output during this test should be 3 times: [wdi5] call of exec failed because of: TypeError: this.getTex is not a function - //Can't be reasonably verified programatically, only that returned result should be null const button = await browser.asControl({ selector: { id: "openDialogButton", @@ -35,6 +44,13 @@ describe("ui5 eval on control", () => { expect(resultArrowFunction1).toBeNull() const resultArrowFunction2 = await button.exec(() => { return this.getTex() }) expect(resultArrowFunction2).toBeNull() + + const expectedExecErrorLog = "call of exec failed because of: TypeError: this.getTex is not a function" + expect(Logger.error.called).toBeTruthy() + expect(Logger.error.callCount).toEqual(3) + expect(Logger.error.getCall(0).calledWith(expectedExecErrorLog)).toBeTruthy() + expect(Logger.error.getCall(1).calledWith(expectedExecErrorLog)).toBeTruthy() + expect(Logger.error.getCall(2).calledWith(expectedExecErrorLog)).toBeTruthy() }) it("execute function browserside on button to get its text, basic return type", async () => { @@ -62,7 +78,7 @@ describe("ui5 eval on control", () => { expect(buttonTextArrow2).toEqual(regularBtnText) }) - it("execute function browserside on button to get its text with fluent sync api, basic return type", async () => { + it("execute function browserside on button to get its text with fluent async api, basic return type", async () => { const buttonText = await browser.asControl({ selector: { id: "openDialogButton",