( element, props, timeout = 4500 )
| 206 | * @return {Promise} |
| 207 | */ |
| 208 | export const waitForElementToHaveCustomProperties = ( |
| 209 | element, |
| 210 | props, |
| 211 | timeout = 4500 |
| 212 | ) => |
| 213 | new Promise((resolve, reject) => { |
| 214 | if (!areCustomCssPropertiesSupported()) { |
| 215 | return resolve(); |
| 216 | } |
| 217 | |
| 218 | const loop = () => { |
| 219 | const hasProps = testElementToHaveCustomProperties(element, props); |
| 220 | |
| 221 | if (hasProps) { |
| 222 | clearTimeout(timeoutHandler); |
| 223 | // This should succeed |
| 224 | expectElementToHaveCustomProperties(element, props); |
| 225 | return resolve(); |
| 226 | } |
| 227 | |
| 228 | // Start in about the next animation frame |
| 229 | requestAnimationFrame(loop); |
| 230 | }; |
| 231 | |
| 232 | const timeoutHandler = setTimeout(() => { |
| 233 | // This should fail the test |
| 234 | expectElementToHaveCustomProperties(element, props); |
| 235 | // The above should've made the test reject, but reject the promise as well regardless |
| 236 | reject( |
| 237 | new Error( |
| 238 | "Timeout on waiting for custom props to change on the given element." |
| 239 | ) |
| 240 | ); |
| 241 | }, timeout); |
| 242 | |
| 243 | loop(); |
| 244 | }); |
| 245 | |
| 246 | /** |
| 247 | * @param {{}} props |
no test coverage detected