diff --git a/packages/@lwc/integration-not-karma/helpers/matchers/errors.js b/packages/@lwc/integration-not-karma/helpers/matchers/errors.js index 668ef31047..f1e17cd64c 100644 --- a/packages/@lwc/integration-not-karma/helpers/matchers/errors.js +++ b/packages/@lwc/integration-not-karma/helpers/matchers/errors.js @@ -36,7 +36,7 @@ function windowErrorListener(callback) { // 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can // only be caught with window.addEventListener('error') // - Note native lifecycle callbacks are all thrown asynchronously. -function customElementCallbackReactionErrorListener(callback) { +export function customElementCallbackReactionErrorListener(callback) { return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE ? directErrorListener(callback) : windowErrorListener(callback); diff --git a/packages/@lwc/integration-not-karma/helpers/utils.js b/packages/@lwc/integration-not-karma/helpers/utils.js index 412cf51e74..3f2ccdaeeb 100644 --- a/packages/@lwc/integration-not-karma/helpers/utils.js +++ b/packages/@lwc/integration-not-karma/helpers/utils.js @@ -2,50 +2,6 @@ * An as yet uncategorized mishmash of helpers, relics of Karma */ -// Listen for errors thrown directly by the callback -function directErrorListener(callback) { - try { - callback(); - } catch (error) { - return error; - } -} - -// Listen for errors using window.addEventListener('error') -function windowErrorListener(callback) { - let error; - function onError(event) { - event.preventDefault(); // don't log the error - error = event.error; - } - - // Prevent jasmine from handling the global error. There doesn't seem to be another - // way to disable this behavior: https://github.com/jasmine/jasmine/pull/1860 - const originalOnError = window.onerror; - window.onerror = null; - window.addEventListener('error', onError); - - try { - callback(); - } finally { - window.onerror = originalOnError; - window.removeEventListener('error', onError); - } - return error; -} - -// For errors we expect to be thrown in the connectedCallback() phase -// of a custom element, there are two possibilities: -// 1) We're using non-native lifecycle callbacks, so the error is thrown synchronously -// 2) We're using native lifecycle callbacks, so the error is thrown asynchronously and can -// only be caught with window.addEventListener('error') -// - Note native lifecycle callbacks are all thrown asynchronously. -export function customElementCallbackReactionErrorListener(callback) { - return lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE - ? directErrorListener(callback) - : windowErrorListener(callback); -} - export function extractDataIds(root) { const nodes = {}; diff --git a/packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/api/index.spec.js b/packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/api/index.spec.js index 22c813fd13..35f76ea431 100644 --- a/packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/api/index.spec.js +++ b/packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/api/index.spec.js @@ -7,7 +7,7 @@ import { ENABLE_ELEMENT_INTERNALS_AND_FACE, IS_SYNTHETIC_SHADOW_LOADED, } from '../../../../helpers/constants.js'; -import { customElementCallbackReactionErrorListener } from '../../../../helpers/utils.js'; +import { customElementCallbackReactionErrorListener } from '../../../../helpers/matchers/errors.js'; const testConnectedCallbackError = (elm, msg) => { const error = customElementCallbackReactionErrorListener(() => { diff --git a/packages/@lwc/integration-not-karma/test/component/LightningElement.connectedCallback/index.spec.js b/packages/@lwc/integration-not-karma/test/component/LightningElement.connectedCallback/index.spec.js index c8f24f45d8..1044788dab 100644 --- a/packages/@lwc/integration-not-karma/test/component/LightningElement.connectedCallback/index.spec.js +++ b/packages/@lwc/integration-not-karma/test/component/LightningElement.connectedCallback/index.spec.js @@ -3,7 +3,7 @@ import { createElement } from 'lwc'; import Test from 'x/test'; import ConnectedCallbackThrow from 'x/connectedCallbackThrow'; import XSlottedParent from 'x/slottedParent'; -import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js'; +import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js'; function testConnectSlot(name, fn) { it(`should invoke the connectedCallback the root element is added in the DOM via ${name}`, () => { diff --git a/packages/@lwc/integration-not-karma/test/component/LightningElement.disconnectedCallback/index.spec.js b/packages/@lwc/integration-not-karma/test/component/LightningElement.disconnectedCallback/index.spec.js index 2b6f4d1fbb..081c94ddc6 100644 --- a/packages/@lwc/integration-not-karma/test/component/LightningElement.disconnectedCallback/index.spec.js +++ b/packages/@lwc/integration-not-karma/test/component/LightningElement.disconnectedCallback/index.spec.js @@ -6,7 +6,7 @@ import DisconnectedCallbackThrow from 'x/disconnectedCallbackThrow'; import DualTemplate from 'x/dualTemplate'; import ExplicitRender from 'x/explicitRender'; import { jasmine } from '../../../helpers/jasmine.js'; -import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js'; +import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js'; function testDisconnectSlot(name, fn) { it(`should invoke the disconnectedCallback when root element is removed from the DOM via ${name}`, () => { diff --git a/packages/@lwc/integration-not-karma/test/component/LightningElement.render/index.spec.js b/packages/@lwc/integration-not-karma/test/component/LightningElement.render/index.spec.js index ddf6b2a9e3..daa1286b94 100644 --- a/packages/@lwc/integration-not-karma/test/component/LightningElement.render/index.spec.js +++ b/packages/@lwc/integration-not-karma/test/component/LightningElement.render/index.spec.js @@ -3,7 +3,7 @@ import { createElement, registerTemplate } from 'lwc'; import DynamicTemplate, { template1, template2 } from 'x/dynamicTemplate'; import RenderThrow from 'x/renderThrow'; import RenderInvalid from 'x/renderInvalid'; -import { customElementCallbackReactionErrorListener } from '../../../helpers/utils.js'; +import { customElementCallbackReactionErrorListener } from '../../../helpers/matchers/errors.js'; function testInvalidTemplate(type, template) { it(`throws an error if returns ${type}`, () => {