auth-guard.service.spec.ts from version 7.3.0 of ngrx/platform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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