Created
March 25, 2015 00:07
-
-
Save guysmoilov/fcf7902890127c2dd78c to your computer and use it in GitHub Desktop.
Can be used inside client integration tests to wait for elements to change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://developer.mozilla.org/en/docs/Web/API/MutationObserver