Skip to content

Commit

Permalink
Throw error for a missing callback
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Oct 4, 2024
1 parent 843e3a9 commit e7513c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 6 additions & 1 deletion javascript/node/selenium-webdriver/lib/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
})

Expand Down

0 comments on commit e7513c9

Please sign in to comment.