Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
puppeteer_tests: Fix type errors.
Anders Kaseorg4ebcc9ba951b
diff --git a/frontend_tests/puppeteer_lib/common.ts b/frontend_tests/puppeteer_lib/common.tsindex 0e0f45c5198..acdbe17bcd6 100644--- a/frontend_tests/puppeteer_lib/common.ts+++ b/frontend_tests/puppeteer_lib/common.ts@@ -103,7 +103,7 @@ class CommonUtils {// This function hacks around that issue; once it's fixed in// puppeteer upstream, we can delete this function and return// its callers to using `page.url()`- return await page.evaluate("location.href");+ return await page.evaluate(() => window.location.href);}// This function will clear the existing value of the element and@@ -280,13 +280,13 @@ class CommonUtils {}async assert_compose_box_content(page: Page, expected_value: string): Promise<void> {- await page.waitForSelector("#compose-textarea");-- const compose_box_element = await page.$("#compose-textarea");- const compose_box_content = await page.evaluate(- (element: HTMLTextAreaElement) => element.value,- compose_box_element,- );+ const compose_box_element = await page.waitForSelector("#compose-textarea");+ const compose_box_content = await page.evaluate((element) => {+ if (!(element instanceof HTMLTextAreaElement)) {+ throw new TypeError("expected HTMLTextAreaElement");+ }+ return element.value;+ }, compose_box_element);assert.equal(compose_box_content,expected_value,@@ -501,12 +501,12 @@ class CommonUtils {`//*[@class="typeahead dropdown-menu" and contains(@style, "display: block")]//li[contains(normalize-space(), "${item}")]//a`,{visible: true},);- const entry_x = (await entry?.boundingBox())?.x;- const entry_y = (await entry?.boundingBox())?.y;- if (entry_x && entry_y) {- await page.mouse.move(entry_x, entry_y);- }+ assert.ok(entry);+ await entry.hover();await page.evaluate((entry) => {+ if (!(entry instanceof HTMLElement)) {+ throw new TypeError("expected HTMLElement");+ }entry.click();}, entry);}diff --git a/frontend_tests/puppeteer_tests/compose.ts b/frontend_tests/puppeteer_tests/compose.tsindex 2bf6aa2d983..729fe1d3345 100644--- a/frontend_tests/puppeteer_tests/compose.ts+++ b/frontend_tests/puppeteer_tests/compose.ts@@ -179,6 +179,7 @@ async function test_markdown_preview_without_any_content(page: Page): Promise<voawait page.click("#compose .markdown_preview");await page.waitForSelector("#compose .undo_markdown_preview", {visible: true});const markdown_preview_element = await page.$("#compose .preview_content");+ assert.ok(markdown_preview_element);assert.equal(await page.evaluate((element: Element) => element.textContent, markdown_preview_element),"Nothing to preview",@@ -189,6 +190,7 @@ async function test_markdown_preview_without_any_content(page: Page): Promise<voasync function test_markdown_rendering(page: Page): Promise<void> {await page.waitForSelector("#compose .markdown_preview", {visible: true});let markdown_preview_element = await page.$("#compose .preview_content");+ assert.ok(markdown_preview_element);assert.equal(await page.evaluate((element: Element) => element.textContent, markdown_preview_element),"",@@ -202,6 +204,7 @@ async function test_markdown_rendering(page: Page): Promise<void> {"<p><strong>Markdown preview</strong> >> Test for Markdown preview</p>";await page.waitForFunction(() => $("#compose .preview_content").html() !== "");markdown_preview_element = await page.$("#compose .preview_content");+ assert.ok(markdown_preview_element);assert.equal(await page.evaluate((element: Element) => element.innerHTML, markdown_preview_element),expected_markdown_html,diff --git a/frontend_tests/puppeteer_tests/settings.ts b/frontend_tests/puppeteer_tests/settings.tsindex 5851ec55875..e7e9adf1bb8 100644--- a/frontend_tests/puppeteer_tests/settings.ts+++ b/frontend_tests/puppeteer_tests/settings.ts@@ -217,6 +217,8 @@ async function test_invalid_edit_bot_form(page: Page): Promise<void> {await page.waitForFunction((cancel_button_selector: string) =>!document.querySelector(cancel_button_selector)?.hasAttribute("disabled"),+ {},+ cancel_button_selector,);await page.click(cancel_button_selector);await page.waitForXPath(