Skip to content

Instantly share code, notes, and snippets.

@jtcrowson
Created March 7, 2019 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtcrowson/fdd258175821b344cd00cc7b2fc3f19f to your computer and use it in GitHub Desktop.
Save jtcrowson/fdd258175821b344cd00cc7b2fc3f19f to your computer and use it in GitHub Desktop.
auth-guard.service.spec.ts from version 7.3.0 of ngrx/platform
// NgRx v7.3.0
describe('Auth Guard', () => {
let guard: AuthGuard;
let store: Store<any>;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
StoreModule.forRoot({
...fromRoot.reducers,
auth: combineReducers(fromAuth.reducers),
}),
],
});
store = TestBed.get(Store);
spyOn(store, 'dispatch').and.callThrough();
guard = TestBed.get(AuthGuard);
});
it('should return false if the user state is not logged in', () => {
const expected = cold('(a|)', { a: false });
expect(guard.canActivate()).toBeObservable(expected);
});
it('should return true if the user state is logged in', () => {
const user: any = {};
const action = new AuthApiActions.LoginSuccess({ user });
store.dispatch(action);
const expected = cold('(a|)', { a: true });
expect(guard.canActivate()).toBeObservable(expected);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment