From e7513c9468f96d276ca689890f295b0c16c9bfb8 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Tue, 20 Aug 2024 13:45:16 +0530 Subject: [PATCH] Throw error for a missing callback --- javascript/node/selenium-webdriver/lib/network.js | 7 ++++++- .../test/lib/webdriver_network_test.js | 11 ++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/javascript/node/selenium-webdriver/lib/network.js b/javascript/node/selenium-webdriver/lib/network.js index 96b1ba50f9d8f..1c55264653484 100644 --- a/javascript/node/selenium-webdriver/lib/network.js +++ b/javascript/node/selenium-webdriver/lib/network.js @@ -75,7 +75,12 @@ class Network { async removeAuthenticationHandler(id) { await this.#init() - this.#authHandlers.delete(id) + + if (this.#authHandlers.has(id)) { + this.#authHandlers.delete(id) + } else { + throw Error(`Callback with id ${id} not found`) + } } async clearAuthenticationHandlers() { diff --git a/javascript/node/selenium-webdriver/test/lib/webdriver_network_test.js b/javascript/node/selenium-webdriver/test/lib/webdriver_network_test.js index ab6df8f90494c..ff1ce496bf038 100644 --- a/javascript/node/selenium-webdriver/test/lib/webdriver_network_test.js +++ b/javascript/node/selenium-webdriver/test/lib/webdriver_network_test.js @@ -88,15 +88,12 @@ suite( } }) - it('can remove authentication handler that does not exist', async function () { - await driver.network().removeAuthenticationHandler(10) - + it('throws an error when remove authentication handler that does not exist', async function () { try { - await driver.get(Pages.basicAuth) - await driver.wait(until.elementLocated(By.css('pre'))) - assert.fail('Page should not be loaded') + await driver.network().removeAuthenticationHandler(10) + assert.fail('Expected error not thrown. Non-existent handler cannot be removed') } catch (e) { - assert.strictEqual(e.name, 'UnexpectedAlertOpenError') + assert.strictEqual(e.message, 'Callback with id 10 not found') } })