Commit 1e121934 authored by Enrique Alcantara's avatar Enrique Alcantara

Fix race condition in lazy_loader spec

parent cbd5d09b
......@@ -45,10 +45,24 @@ describe('LazyLoader', () => {
return newImg;
};
const mockLoadEvent = () => {
const addEventListener = window.addEventListener.bind(window);
jest.spyOn(window, 'addEventListener').mockImplementation((event, callback) => {
if (event === 'load') {
callback();
} else {
addEventListener(event, callback);
}
});
};
beforeEach(() => {
jest.spyOn(window, 'requestAnimationFrame').mockImplementation(execImmediately);
jest.spyOn(window, 'requestIdleCallback').mockImplementation(execImmediately);
jest.spyOn(LazyLoader, 'loadImage');
mockLoadEvent();
});
afterEach(() => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment