gitlab-org--gitlab-foss/spec/frontend/helpers/wait_for_attribute_change.js
Winnie Hellmann 2e7486681a Copy missing helpers from Karma to Jest
Copy missing helpers from Karma to Jest
2019-03-28 20:07:40 +01:00

16 lines
506 B
JavaScript

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 });
});