MCPcopy Index your code
hub / github.com/ZeeCoder/container-query / waitForElementToHaveStyle

Function waitForElementToHaveStyle

tests/utils/index.js:124–152  ·  view source on GitHub ↗
(element, style, timeout = 4500)

Source from the content-addressed store, hash-verified

122 * @return {Promise}
123 */
124export 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

Callers 5

index.jsFile · 0.90
index.jsFile · 0.90
index.jsFile · 0.90

Calls 2

expectElementToHaveStyleFunction · 0.85
loopFunction · 0.85

Tested by

no test coverage detected