Skip to content

Instantly share code, notes, and snippets.

@d4hines
Created July 22, 2017 23:07
Show Gist options
  • Save d4hines/7b5fceb4a3eb53e050b9066800a02ccb to your computer and use it in GitHub Desktop.
Save d4hines/7b5fceb4a3eb53e050b9066800a02ccb to your computer and use it in GitHub Desktop.
Why aren't either of these tests passing?
import { Router } from '@angular/router';
import { TestBed } from '@angular/core/testing';
import { EffectsModule } from '@ngrx/effects';
import { provideMockActions } from '@ngrx/effects/testing';
import { Observable } from 'rxjs/Observable';
import { ReplaySubject } from 'rxjs/ReplaySubject';
import { AuthEffects } from './auth.effects';
import * as fromAuth from '../actions/auth';
import { AuthService } from '../services/auth.service';
describe('Auth Effects', () => {
let effects: AuthEffects;
let actions: ReplaySubject<fromAuth.Actions>;
// Stub Auth Service
const username = 'SomeUserName';
class StubAuthService extends AuthService {
checkAuth() { return Observable.from([username]); }
}
// Stub Router Service
class StubRouter {
navigateByUrl(url: string) {
return url;
}
}
beforeEach(() => {
TestBed.configureTestingModule({
providers: [
AuthEffects,
provideMockActions(() => actions),
{ provide: AuthService, useClass: StubAuthService },
{ provide: Router, useClass: StubRouter },
],
});
effects = TestBed.get(AuthEffects);
});
it('Should be created', () => {
expect(effects).toBeTruthy();
});
it('should map CheckLogin to LoginSuccess if there are no errors', () => {
actions = new ReplaySubject(1); // Caches results, plays back when subscribed to.
actions.next(new fromAuth.CheckLogin());
effects.checkLogin$.subscribe(result =>
expect(result).toEqual(new fromAuth.LoginSuccess({ user: { name: username } })),
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment