Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda