UNPKG

@funnelenvy-npm/fe-dev-utils

Version:

Helper function to build client side A/B tests

22 lines (21 loc) 1.32 kB
/** * Get elements matching a CSS selector. Waits for the elements to exist and returns a promise. * @param {Object} options - Options object to configure the function. * @param {Array|string} options.condition - The CSS selector to match elements. * @param {string} [options.activity] - (Optional) Name of the activity the function is being called from, if onError is not set this will be used in the * @param {number} [options.outTimer=10000] - (Optional) The maximum time in milliseconds to wait for the elements to exist. Default is 10000ms. * @param {function} [errorHandler=null] - (Optional) A callback function to handle errors during the waiting process. If not provided, errors will be logged to the console. * @returns {Promise} A promise that resolves with an object containing the selector and matching elements once they are found. * @throws {TypeError} If the timeout is reached and the elements are not found. */ type GetElementOptions = { condition: string | string[]; activity?: string; errorHandler?: ((params: { activity: string; error: Error; }) => void) | null; outTimer?: number; }; declare const getElement: ({ condition, activity, errorHandler, outTimer, }: GetElementOptions) => Promise<Record<string, NodeListOf<Element>>>; export default getElement;