(element, style, timeout = 4500)
| 122 | * @return {Promise} |
| 123 | */ |
| 124 | export const waitForElementToHaveStyle = (element, style, timeout = 4500) => |
| 125 | new Promise((resolve, reject) => { |
| 126 | const loop = () => { |
| 127 | const hasStyle = testElementToHaveStyle(element, style); |
| 128 | |
| 129 | if (hasStyle) { |
| 130 | clearTimeout(timeoutHandler); |
| 131 | // This should succeed |
| 132 | expectElementToHaveStyle(element, style); |
| 133 | return resolve(); |
| 134 | } |
| 135 | |
| 136 | // Start in about the next animation frame |
| 137 | requestAnimationFrame(loop); |
| 138 | }; |
| 139 | |
| 140 | const timeoutHandler = setTimeout(() => { |
| 141 | // This should fail the test |
| 142 | expectElementToHaveStyle(element, style); |
| 143 | // The above should've made the test reject, but reject the promise as well regardless |
| 144 | reject( |
| 145 | new Error( |
| 146 | "timeout on waiting for styles to change on the given element" |
| 147 | ) |
| 148 | ); |
| 149 | }, timeout); |
| 150 | |
| 151 | loop(); |
| 152 | }); |
| 153 | |
| 154 | /** |
| 155 | * @param {{}} style |
no test coverage detected