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

92
Visualizações
Change Radio button value Angular Jasmine Testing

I have two radio buttons, first one checked. Now, in my test file, I want to check the second radio button and then continue testing further. I am not finding a way to do so.

Following is my radio button:

<div class="form-check form-check-inline">
      <input class="form-check-input" type="radio" name="RadioButton" (change)="some_func(true)" checked>
      <label class="form-check-label" for="inlineRadio1">Radio1</label>
 </div>
 <div class="form-check form-check-inline">
       <input class="form-check-input" type="radio" name="RadioButton" (change)="some_func(false)">
       <label class="form-check-label" for="inlineRadio2">Radio2</label>
</div>

I tried the following to change my radio button value, but it doesn't work :

let options: DebugElement[] = fixture.debugElement.queryAll(By.css('input[type="radio"]'));
options[1].triggerEventHandler('change', { target: options[1].nativeElement });

Can someone help me here, how can I make the second radio button checked?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I think you can find a solution here :

Jasmine test for checkbox change handler function in angular 12

  • You would need to run detectChanges()
  • You can access both your radio with :

options[0].triggerEventHandler('change', { target: { checked: true } });

options[1].triggerEventHandler('change', { target: { checked: true } });

about 4 years ago · Juan Pablo Isaza Relatório

0

Cypress has its own api for interacting with elements link

        <div
            class="form-check form-check-inline"
            data-cy="form-check-label"
          >
            <input type="checkbox" />
...

cy.get('[data-cy=form-check-label]').find('input').check()

Imagine div wrapped your input, you would use find() on its child input and call check(). Use data-cy=some_name to give your elements cypress specific selectors, then you know if element attributes change e.g class your tests won't be affected.

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