sidebar.component.spec.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { async, ComponentFixture, TestBed } from "@angular/core/testing";
  2. import { SidebarComponent } from "./sidebar.component";
  3. import { By } from "@angular/platform-browser";
  4. import { RouterLinkWithHref } from "@angular/router";
  5. import { RouterTestingModule } from "@angular/router/testing";
  6. import { HttpClientModule } from "@angular/common/http";
  7. import { AuthService } from "../../../services/auth2.service";
  8. describe("SidebarComponent", () => {
  9. let component: SidebarComponent;
  10. let fixture: ComponentFixture<SidebarComponent>;
  11. beforeEach(async(() => {
  12. TestBed.configureTestingModule({
  13. declarations: [SidebarComponent],
  14. imports: [RouterTestingModule, HttpClientModule],
  15. providers: [AuthService]
  16. }).compileComponents();
  17. }));
  18. beforeEach(() => {
  19. fixture = TestBed.createComponent(SidebarComponent);
  20. component = fixture.componentInstance;
  21. fixture.detectChanges();
  22. });
  23. it("should create", () => {
  24. expect(component).toBeTruthy();
  25. });
  26. it("Debe de tener un link a la página root", () => {
  27. const elementos = fixture.debugElement.queryAll(
  28. By.directive(RouterLinkWithHref)
  29. );
  30. // console.log( elementos );
  31. let existe = false;
  32. for (const elem of elementos) {
  33. console.log(elem.attributes);
  34. if (elem.attributes["ng-reflect-router-link"] === "/dashboard") {
  35. existe = true;
  36. break;
  37. }
  38. }
  39. expect(existe).toBeTruthy();
  40. });
  41. });