MCPcopy
hub / github.com/docsifyjs/docsify / waitForText

Function waitForText

test/helpers/wait-for.js:92–126  ·  view source on GitHub ↗

* 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 = {})

Source from the content-addressed store, hash-verified

90 * @returns {Promise} promise which resolves to first matching element that contains specified text
91 */
92function 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
128module.exports = {
129 waitForFunction,

Callers 1

example.test.jsFile · 0.85

Calls 1

waitForSelectorFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…