Skip to content

Commit ff39137

Browse files
committed
Throw error for a missing callback
1 parent 575735b commit ff39137

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

javascript/node/selenium-webdriver/lib/network.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ class Network {
7575

7676
async removeAuthenticationHandler(id) {
7777
await this.#init()
78-
this.#authHandlers.delete(id)
78+
79+
if (this.#authHandlers.has(id)) {
80+
this.#authHandlers.delete(id)
81+
} else {
82+
throw Error(`Callback with id ${id} not found`)
83+
}
7984
}
8085

8186
async clearAuthenticationHandlers() {

javascript/node/selenium-webdriver/test/lib/webdriver_network_test.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,12 @@ suite(
8888
}
8989
})
9090

91-
it('can remove authentication handler that does not exist', async function () {
92-
await driver.network().removeAuthenticationHandler(10)
93-
91+
it('throws an error when remove authentication handler that does not exist', async function () {
9492
try {
95-
await driver.get(Pages.basicAuth)
96-
await driver.wait(until.elementLocated(By.css('pre')))
97-
assert.fail('Page should not be loaded')
93+
await driver.network().removeAuthenticationHandler(10)
94+
assert.fail('Expected error not thrown. Non-existent handler cannot be removed')
9895
} catch (e) {
99-
assert.strictEqual(e.name, 'UnexpectedAlertOpenError')
96+
assert.strictEqual(e.message, 'Callback with id 10 not found')
10097
}
10198
})
10299

0 commit comments

Comments
 (0)