Skip to content

Commit

Permalink
test: add unit tests for error utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
saikumarrs committed Nov 7, 2024
1 parent f9b7a6c commit 0d9dd95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions packages/analytics-js-common/__tests__/utilities/errors.test.ts
Original file line number Diff line number Diff line change
@@ -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 }));
});
});
});
3 changes: 2 additions & 1 deletion packages/analytics-js/src/components/core/Analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
}
Expand Down

0 comments on commit 0d9dd95

Please sign in to comment.