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

301
Visualizações
How to write test case for @viewchild element referenced for input type checkbox in angular 8?

I am new to angular test case. I have a input type checkbox which has element ref id of #checkbox. Below is code snippet. How to write test case for masterToggle function in below code? If anyone know please help to find the solution.

app.component.ts:

@ViewChild('checkbox') checkbox;

function masterToggle(){
this.checkbox.nativeElement.checked = false;
this.checkbox.nativeElement.indeterminate = false;
}

HTML :

<input type="checkbox" class="nodecheckbox" #checkbox [disabled]="isCheckboxDisabledForSelectAll()" (change)="masterToggle(data)" >
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The purpose of testing is to verify, if a functionality is behaving accordingly to the dev expectation. Starting from here we should test if masterToggle method sets checked property to false and indeterminate to false.

Inside a test file in Angular you have access to all public methods, and eventually by using bracket notation(Mycomponent[privateMethodOrPropertyName]). So this actually allows you for easy testing.

it('should be ok', async(() => {
    let fixture = TestBed.createComponent(TestComponent);
    fixture.detectChanges();
    fixture.whenStable().then(() => {
      let checkbox = fixture.debugElement.query(/*you should locate yourcheckbox*/);

      component.masterToggle();
      // if model doesn't update use fixture.detectChanges();

      expect(checkbox.nativeElement.checked).toBe(False);
      expect(checkbox.nativeElement.indeterminate).toBe(False);
    });
about 4 years ago · Juan Pablo Isaza Relatório
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