I am trying to trigger a scroll event inside of my unit test using Mocha running in a browser. I have the following code:
describe('Background Change', function() {
describe('toogleBgHandler()', function() {
it('should contain toggle-bg when scrollTop is more than 0', function() {
let target = [{scrollTop : 10}];
let body = document.createElement('body');
let div = document.createElement('div');
body.appendChild(div);
window.scrollBy(0, 100);
console.log(window.pageYOffset); // this returns 0, why?
toggleBgHandler(target, div); // depends on the scroll event
chai.assert.isTrue(div.classList.contains("toggle-bg"));
});
});
});
How do I trigger a scroll event for a function that depends on it? I have also tried creating an event object, but that didn't work either. Any pointers would be great.
Aucun commentaire:
Enregistrer un commentaire