1.  
  2. let userServiceStub: Partial;
  3. beforeEach(() => {
  4. // stub UserService for test purposes
  5. userServiceStub = {
  6. isLoggedIn: true,
  7. user: { name: 'Test User'}
  8. };
  9. TestBed.configureTestingModule({
  10. declarations: [ WelcomeComponent ],
  11. providers: [ {provide: UserService, useValue: userServiceStub } ]
  12. });
  13. fixture = TestBed.createComponent(WelcomeComponent);
  14. comp = fixture.componentInstance;
  15. // UserService from the root injector
  16. userService = TestBed.get(UserService);
  17. // get the "welcome" element by CSS selector (e.g., by class name)
  18. el = fixture.nativeElement.querySelector('.welcome');
  19. });