function waitForText(cssSelector, text, options = {}) {
  const settings = {
    ...defaults,
    ...options,
  };

  return new Promise((resolve, reject) => {
    let timeElapsed = 0;

    waitForSelector(cssSelector, settings)
      .then(elm => {
        const int = setInterval(() => {
          const isMatch = elm.textContent.includes(text);

          if (isMatch) {
            clearInterval(int);
            resolve(true);
          }

          timeElapsed += settings.delay;

          if (timeElapsed >= settings.timeout) {
            const msg = `waitForText did not find '${text}' in CSS selector '${cssSelector}' (${settings.timeout} ms): '${elm.textContent}'`;

            reject(msg);
          }
        }, settings.delay);
      })
      .catch(() => {
        const msg = `waitForText did not match CSS selector '${cssSelector}' (${settings.timeout} ms)`;

        reject(msg);
      });
  });
}
Waits for specified CSS selector to contain text content

@param {String} cssSelector CSS selector to query for
@param {String} text text to match
@param {Object} options optional parameters
@param {number} options.delay delay between checks
@param {number} options.timeout timeout in milliseconds
@returns {Promise} promise which resolves to first matching element that contains specified text