Mocking RouterStateSnapshot in Jasmine testing
<p>Although I have been writing Angular 2 for a while now, I am only just writing my first Jasmine tests and have run into a little difficulty. I am trying to test that the <code>CanActivate</code> method of service implementing <code>CanActivate</code> is behaving itself, and is returning <code>true</code> or <code>false</code> as expected.</p>

<p>My method looks like this:</p>

<pre><code>canActivate( route: ActivatedRouteSnapshot, state: RouterStateSnapshot ): Observable&lt;boolean&gt; {
    return this.store$
        .map( ( store: StoreState ) =&gt; store.currentUser )
        .first()
        .map( ( user ) =&gt; {
            if ( user.isAuthenticated ) {
                return true;
            }

            // TODO: This needs refactoring. Need to provide RouterStateSnapshot in test,
            // rather than ignoring it!
            this.redirectUrl = state ? state.url : '';
            this.injector.get( Router ).navigate( ['/login'] );
            return false;
        } );
}
</code></pre>

<p>An extract of my test looks like this:</p>

<pre><code>service = TestBed.get( AuthGuardService );

it( 'should prevent navigation', () =&gt; {
    service.canActivate(null, null).subscribe((res) =&gt; expect( res ).toBeTruthy() );
} );
</code></pre>

<p>How do I mock/stub/whatever the second parameter of my call to <code>service.canActivate</code>, rather than simply passing in null?</p>