diff --git a/packages/analytics-js-common/__tests__/utilities/errors.test.ts b/packages/analytics-js-common/__tests__/utilities/errors.test.ts new file mode 100644 index 000000000..f682c69ce --- /dev/null +++ b/packages/analytics-js-common/__tests__/utilities/errors.test.ts @@ -0,0 +1,13 @@ +import { dispatchErrorEvent } from '../../src/utilities/errors'; + +describe('Errors - utilities', () => { + describe('dispatchErrorEvent', () => { + it('should dispatch an error event', () => { + const dispatchEvent = jest.fn(); + globalThis.dispatchEvent = dispatchEvent; + const error = new Error('Test error'); + dispatchErrorEvent(error); + expect(dispatchEvent).toHaveBeenCalledWith(new ErrorEvent('error', { error })); + }); + }); +}); diff --git a/packages/analytics-js/src/components/core/Analytics.ts b/packages/analytics-js/src/components/core/Analytics.ts index 2b28c1043..ed6986769 100644 --- a/packages/analytics-js/src/components/core/Analytics.ts +++ b/packages/analytics-js/src/components/core/Analytics.ts @@ -180,7 +180,8 @@ class Analytics implements IAnalytics { break; } } catch (err) { - this.errorHandler.onError(getMutatedError(err, 'Life cycle failure'), ANALYTICS_CORE); + const issue = 'Failed to load the SDK'; + this.errorHandler.onError(getMutatedError(err, issue), ANALYTICS_CORE); } }); }