debian-mirror-gitlab/spec/javascripts/helpers/wait_for_attribute_change.js

17 lines
506 B
JavaScript
Raw Normal View History

2018-12-23 12:14:25 +05:30
export default (domElement, attributes, timeout = 1500) =>
new Promise((resolve, reject) => {
let observer;
const timeoutId = setTimeout(() => {
observer.disconnect();
reject(new Error(`Could not see an attribute update within ${timeout} ms`));
}, timeout);
observer = new MutationObserver(() => {
clearTimeout(timeoutId);
observer.disconnect();
resolve();
});
observer.observe(domElement, { attributes: true, attributeFilter: attributes });
});