title: angular jasmine spyOn($window, 'addEventListener'); not work
body: <p>Can't understand why this code not work?</p>
  
  <p>Error is:</p>
  
  <pre><code>Expected spy addEventListener to have been called with [ 'scroll', &lt;jasmine.any(Function)&gt;, true ] but it was never called.
  </code></pre>
  
  <p>.</p>
  
  <pre><code>describe('sessionActivity.spec', () =&gt; {
      beforeEach(module('sessionActivity'));
  
      it('should subscribe', inject(($window, sessionActivity) =&gt; {
          spyOn($window, 'addEventListener');
  
          sessionActivity.subscribe();
          //$window.addEventListener('scroll', () =&gt; {}, true);
          //$window.addEventListener('click', () =&gt; {}, true);
          expect($window.addEventListener).toHaveBeenCalledWith('scroll', jasmine.any(Function), true);
          expect($window.addEventListener).toHaveBeenCalledWith('click', jasmine.any(Function), true);
      }));
  });
  </code></pre>
  
  <p>Inside a sessionActivity.subscribe I create two events listeners.</p>
  
  <p>And also if I uncomment two lines with //$window.addEventListener all test is pass.</p>
  
  <p>What I should change here?</p>
  
  <p><strong>EDITED:</strong></p>
  
  <p>The problem was that I used shortcut inside sessionActivity.subscribe():</p>
  
  <pre><code>const { addEventListener, removeEventListener } = $window;
  addEventListener('scroll', trackActivityWithDebounce, true);
  addEventListener('click', trackActivityWithDebounce, true);
  </code></pre>
  
  <p>Can some one explain this?</p>