* 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 * @returns {Promise} promise which resolves to first matching element that contains specified t
(cssSelector, text, options = {})
| 90 | * @returns {Promise} promise which resolves to first matching element that contains specified text |
| 91 | */ |
| 92 | function waitForText(cssSelector, text, options = {}) { |
| 93 | const settings = { |
| 94 | ...defaults, |
| 95 | ...options, |
| 96 | }; |
| 97 | |
| 98 | return new Promise((resolve, reject) => { |
| 99 | let timeElapsed = 0; |
| 100 | |
| 101 | waitForSelector(cssSelector, settings) |
| 102 | .then(elm => { |
| 103 | const int = setInterval(() => { |
| 104 | const isMatch = elm.textContent.includes(text); |
| 105 | |
| 106 | if (isMatch) { |
| 107 | clearInterval(int); |
| 108 | resolve(true); |
| 109 | } |
| 110 | |
| 111 | timeElapsed += settings.delay; |
| 112 | |
| 113 | if (timeElapsed >= settings.timeout) { |
| 114 | const msg = `waitForText did not find '${text}' in CSS selector '${cssSelector}' (${settings.timeout} ms): '${elm.textContent}'`; |
| 115 | |
| 116 | reject(msg); |
| 117 | } |
| 118 | }, settings.delay); |
| 119 | }) |
| 120 | .catch(() => { |
| 121 | const msg = `waitForText did not match CSS selector '${cssSelector}' (${settings.timeout} ms)`; |
| 122 | |
| 123 | reject(msg); |
| 124 | }); |
| 125 | }); |
| 126 | } |
| 127 | |
| 128 | module.exports = { |
| 129 | waitForFunction, |
no test coverage detected
searching dependent graphs…