Daniel Delgado
Daniel Delgado

Reputation: 5323

Getting the checked value of a mat-checkbox - Angular Material

I'm trying to get the value (true or false) of a checked input control

it('Is checkbox checked', () => {
  cy.get('mat-checkbox[formcontrolname=favorite]').should('be.checked')
})

But the assertion always fails

Upvotes: 0

Views: 1025

Answers (2)

Daniel Delgado
Daniel Delgado

Reputation: 5323

I had to find the native input

it('Is checkbox checked', () => {
  cy.get('mat-checkbox[formcontrolname=favorite] input').should('be.checked')
})

Upvotes: 0

Chris
Chris

Reputation: 2417

You must access the native input

it('Is checkbox checked', () => {
  cy
    .get('mat-checkbox[formcontrolname=favorite]')
    .get('[type="checkbox"]')
    .check()
})

Upvotes: 1

Related Questions