From 3e496df720ecf0172fabc3412156f5c60ea68061 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 8 Nov 2024 13:56:26 +0100 Subject: [PATCH] Fix null case --- packages/e2e-tests/src/puppeteerEnvironment.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/e2e-tests/src/puppeteerEnvironment.js b/packages/e2e-tests/src/puppeteerEnvironment.js index 4cab03d76770..e19c0679fc6c 100644 --- a/packages/e2e-tests/src/puppeteerEnvironment.js +++ b/packages/e2e-tests/src/puppeteerEnvironment.js @@ -40,8 +40,11 @@ class PuppeteerEnvironment extends JestPuppeteer.TestEnvironment { async handleTestEvent(event, state) { if (event.name === 'test_fn_failure' || event.name === 'hook_failure') { - const testName = `${state.currentlyRunningTest.parent.name} ${state.currentlyRunningTest.name}`; - const errors = state.currentlyRunningTest.errors; + const testName = + event.name === 'test_fn_failure' + ? `${state.currentlyRunningTest.parent.name} ${state.currentlyRunningTest.name}` + : 'before or after hook'; + const errors = state.currentlyRunningTest?.errors || []; const eventError = util.inspect(event); let errorMessages = ''; errorMessages += `========= ${testName} ==========\n\n`;