I have a (rather poorly written) javascript component in my application that handles page numbering with infinite scroll, and I'm trying to rewrite it to use IntersectionObserveras described here , however, I'm having problems testing.
Is there a way to control the observer behavior in the QUnit test, that is, to trigger the observer callback with some entries described in my tests?
A possible solution I found is to present a callback function in the component prototype and call it directly in my test, something like this:
InfiniteScroll.prototype.observerCallback = function(entries) {
}
InfiniteScroll.prototype.initObserver = function() {
var io = new IntersectionObserver(this.observerCallback);
io.observe(someElements);
}
var component = new InfiniteScroll();
component.observerCallback(someEntries);
, , IntersectionObserver , , , , , ?
, jQuery :)