replaced timeouts with load event listeners to improve matchMedia test stability