I needed to add this line as in the karma.spec.js, the mocks for window.open and document.getElementById did not work when clearContext is being called.