Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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