Angular 7: Test Guard

I will show you how you can test a guard. I'd like to test the code below:



We have in this code mainly 3 cases to test:
  1. The logged in user has the required role. He should be able to access the restricted area.
  2. The logged in user has NOT the required role. He should not be able to access the restricted area. The user is redirected to the home page.
  3. The user is NOT logged in. He should not be able to access the restricted area. The user is redirected to the login page.



You can run your test with ng test. You should see something like that:


Thanks for sharing...

Comments

Popular posts from this blog

Spring JPA : Using Specification with Projection

Chip input using Reactive Form