Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Can be used inside client integration tests to wait for elements to change
observeMutationsHelper = function(targetSelector, done, callback) {
var target = document.querySelector(targetSelector);
var observer = new MutationObserver(function(mutations) {
callback(mutations);
observer.disconnect();
done();
});
var config = {
attributes: true,
childList: true,
characterData: true
};
observer.observe(target, config);
};
describe('header', function() {
it("should change after some event", function(done) {
var btn = $("#change-header");
expect($('h1').textContent).toEqual('old header');
// Wait for header to change using MutationObserver, not part of meteor but a browser API
observeMutationsHelper('h1', done, function(mutations) {
expect(mutations[0].target.textContent).toEqual("new header");
});
btn.click();
});
});
@guysmoilov

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment