feat: Add chatwoot:error sdk event (#3998)
This commit is contained in:
@@ -1,15 +1,15 @@
|
||||
export const createEvent = eventName => {
|
||||
export const createEvent = ({ eventName, data = null }) => {
|
||||
let event;
|
||||
if (typeof window.CustomEvent === 'function') {
|
||||
event = new CustomEvent(eventName);
|
||||
event = new CustomEvent(eventName, { detail: data });
|
||||
} else {
|
||||
event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent(eventName, false, false, null);
|
||||
event.initCustomEvent(eventName, false, false, data);
|
||||
}
|
||||
return event;
|
||||
};
|
||||
|
||||
export const dispatchWindowEvent = eventName => {
|
||||
const event = createEvent(eventName);
|
||||
export const dispatchWindowEvent = ({ eventName, data }) => {
|
||||
const event = createEvent({ eventName, data });
|
||||
window.dispatchEvent(event);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ import { dispatchWindowEvent } from '../CustomEventHelper';
|
||||
describe('dispatchWindowEvent', () => {
|
||||
it('dispatches correct event', () => {
|
||||
window.dispatchEvent = jest.fn();
|
||||
dispatchWindowEvent('chatwoot:ready');
|
||||
dispatchWindowEvent({ eventName: 'chatwoot:ready' });
|
||||
expect(dispatchEvent).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user