UNPKG

ashish-sdk

Version:
49 lines 1.73 kB
/** Initialises fetch to the global object */ global.fetch = jest.fn(() => Promise.resolve({ json: () => ({ mixpanelAccessToken: '' }), })); export const getDocumentBody = () => '<div id="embed"></div><div id="embed-2"></div>'; export const getRootEl = () => document.getElementById('embed'); export const getRootEl2 = () => document.getElementById('emebed-2'); export const getIFrameEl = (container = document) => container.querySelector('iframe'); export const getAllIframeEl = () => document.querySelectorAll('iframe'); export const getIFrameSrc = (container = document) => getIFrameEl(container).src; /** * jsdom does not set event source, therefore we do it * programmatically and use dispatchEvent instead of the * postMessage API * Reference: https://github.com/jsdom/jsdom/issues/2745 * @param window * @param data */ export const postMessageToParent = (window, data, port) => { const message = new MessageEvent('message', { data, source: window, ports: [port], }); window.parent.dispatchEvent(message); }; /** * Execute a given function after a certain time has elapsed * @param fn The function to be executed after the wait period * @param waitTime The wait period in milliseconds */ export const executeAfterWait = (fn, waitTime = 0) => { return new Promise((resolve, reject) => { setTimeout(() => { const value = fn(); resolve(value); }, waitTime); }); }; /** * Time (in milliseconds) to wait for async events to be triggered */ export const EVENT_WAIT_TIME = 1000; export function fixedEncodeURI(str) { return encodeURI(str).replace(/%5B/g, '[').replace(/%5D/g, ']'); } //# sourceMappingURL=test-utils.js.map