Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

103
Vistas
Angular unit test verifying childcomponent's method call

I have a page with sidebar section with sidebar-component and content section with a page-component. From the page-component, when I click a button, the sidebar-component toggles. Below is the code,

  async onSidebarButtonPressed() {
    const sidebar = document.querySelector('#filter-sidebar');
    console.log(sidebar);
    (sidebar as any)?.toggle();
  }

Now I want to cover the scenario where the

toggle()

is called. I tried stubing the sidebar-component,

  @Component({ selector: 'cf-wc-sidebar-filter-v9', template: '' })
    class SidebarStubComponent {
      toggle() { /* */}
    }
..
..
..


      it('should toggle sidebar action', async () => {
              const sidebarSpy= spyOn(document,'querySelector').and.callFake(()=>SidebarStubComponent);
   fixture.detectChanges();

  await component.onSidebarButtonPressed();

  });

I am getting an error "_a.toggle is not a function". Initially I tried with state and the tech guys told not to use state for this. I tried with @ViewChild and it comes undefined. Since these 2 components are completely disconnected

How else can I test this scenario?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda