Jasmine.js Testing - spy on window.open
<p><strong>JS</strong></p>

<pre><code>var link = this.notificationDiv.getElementsByTagName('a')[0];

link.addEventListener('click', function (evt){
    evt.preventDefault();
    visitDestination(next);
  }, false);
}

var visitDestination = function(next){
    window.open(next)
}
</code></pre>

<p><strong>Spec</strong></p>

<pre><code>  var next = "http://www.example.com"

  it( 'should test window open event', function() {

    var spyEvent = spyOnEvent('#link', 'click' ).andCallFake(visitDestination(next));;
    $('#link')[0].click();
    expect( 'click' ).toHaveBeenTriggeredOn( '#link' );
    expect( spyEvent ).toHaveBeenTriggered();

    expect(window.open).toBeDefined();
    expect(window.open).toBe('http://www.example.com');    
 });
</code></pre>

<p>How to write the spec to test for when link is clicked it calls <code>visitDestination</code> and to ensures <code>window.open == next</code>? When I try to run the spec it opens the new window. </p>