diff --git a/packages/expect-puppeteer/src/matchers/notToMatch.js b/packages/expect-puppeteer/src/matchers/notToMatch.js index c9d420cf..77b609ce 100644 --- a/packages/expect-puppeteer/src/matchers/notToMatch.js +++ b/packages/expect-puppeteer/src/matchers/notToMatch.js @@ -1,7 +1,7 @@ async function notToMatch(page, matcher, options = { timeout: 500 }) { try { await page.waitForFunction( - `document.body.textContent.match(new RegExp('${matcher}')) === null`, + `document.body && document.body.textContent.match(new RegExp('${matcher}')) === null`, options, ) } catch (error) { diff --git a/packages/expect-puppeteer/src/matchers/toMatch.js b/packages/expect-puppeteer/src/matchers/toMatch.js index c04e5ca3..29fb44ed 100644 --- a/packages/expect-puppeteer/src/matchers/toMatch.js +++ b/packages/expect-puppeteer/src/matchers/toMatch.js @@ -1,7 +1,7 @@ async function toMatch(page, matcher, options = { timeout: 500 }) { try { await page.waitForFunction( - `document.body.textContent.match(new RegExp('${matcher}')) !== null`, + `document.body && document.body.textContent.match(new RegExp('${matcher}')) !== null`, options, ) } catch (error) {