From 1f011d8e02f699f8d548fd4b2efce0d8d4e4ffbf Mon Sep 17 00:00:00 2001 From: sun0day Date: Fri, 31 Mar 2023 01:22:08 +0800 Subject: [PATCH] test: throw element not found error (#12665) --- playground/test-utils.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/playground/test-utils.ts b/playground/test-utils.ts index b99daa846b2689..137abff2c4bd53 100644 --- a/playground/test-utils.ts +++ b/playground/test-utils.ts @@ -71,7 +71,11 @@ const timeout = (n: number) => new Promise((r) => setTimeout(r, n)) async function toEl(el: string | ElementHandle): Promise { if (typeof el === 'string') { - return await page.$(el) + const realEl = await page.$(el) + if (realEl == null) { + throw new Error(`Cannot find element: "${el}"`) + } + return realEl } return el }