feat: Add chatwoot:ready event listener on window (#1091)

* feat: Add `chatwoot:ready` event listener on window

* Add specs

* Rename customEventHelper.js -> CustomEventHelper.js
This commit is contained in:
Pranav Raj S
2020-07-25 21:54:58 +05:30
committed by GitHub
parent 80b083c7fc
commit 12ee7e5d82
5 changed files with 42 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
export const createEvent = eventName => {
let event;
if (typeof window.CustomEvent === 'function') {
event = new CustomEvent(eventName);
} else {
event = document.createEvent('CustomEvent');
event.initCustomEvent(eventName, false, false, null);
}
return event;
};
export const dispatchWindowEvent = eventName => {
const event = createEvent(eventName);
window.dispatchEvent(event);
};

View File

@@ -0,0 +1,9 @@
import { dispatchWindowEvent } from '../CustomEventHelper';
describe('dispatchWindowEvent', () => {
it('dispatches correct event', () => {
window.dispatchEvent = jest.fn();
dispatchWindowEvent('chatwoot:ready');
expect(dispatchEvent).toHaveBeenCalled();
});
});