title: angular 2 testing - stubing a window open and flush interval
body: <p>I need to unit test this part of my code in MyService</p>
  
  <pre><code>social(someUrl){
      let intervalTimer = Observable.interval(1000);
  
      let authWindow = window.open(someUrl);
  
      let  pingWindow = intervalTimer.subscribe(()=&gt;{
          if(authWindow.closed){
              pingWindow.unsubscribe();
              return this.http.get(...)
          }
      })
  }
  </code></pre>
  
  <p>it pops up with some Url which calls to execute some function in my backend and once it's done, it will be redirected to an empty page which closes the pop up (so just window.close() in the script)</p>
  
  <p>So basically the code above checks every second if the pop up is still open, if not it unsubscribes and returns a http.get request as Observable.</p>
  
  <p>I have two major questions:</p>
  
  <ol>
  <li>How to stub the window.open and test, that someUrl is being used, I've read that so far you can only use jasmine? In Sinon you have sinon.stub(window, 'open',()=>{})</li>
  <li>how to test the http.get inside the interval? I'm getting this error</li>
  </ol>
  
  <blockquote>
    <p>1 periodic timer(s) still in the queue.</p>
  </blockquote>
  
  <p>this is my test.spect setup</p>
  
  <pre><code>const mockHttpProvider = {
      deps: [MockBackend, BaseRequestOptions],
      useFactory: (backend: MockBackend, defaultOptions: BaseRequestOptions) =&gt; {
          return new Http(backend, defaultOptions)
      }
  };
  
  describe('my Test', () =&gt; {
  
  beforeEachProviders(() =&gt; {
      return [
          MyService,
          MockBackend,
          BaseRequestOptions,
          provide(Http, mockHttpProvider)
      ]
  });
  
  it('should...', inject([MyService, MockBackend], fakeAsync((myService: MyService, backend: MockBackend) =&gt; {
  
          backend.connections.subscribe((connection: MockConnection) =&gt; {
  ???
          });
  
          myService.social().subscribe(res =&gt; {
               ???
          });
      })))
  </code></pre>
  
  <p>thanks!</p>