Home > Enterprise >  Cypress - Get [value] value property from mat-button-toggle-group
Cypress - Get [value] value property from mat-button-toggle-group

Time:02-04

I have a selector to <mat-button-toggle-group [value]="myValue"></mat-button-toggle-group>

I want to have access to [value] value, and for that I do.

buttonToggleGroupSelector.should('exist').and('has.value', 'MyValue');

But this returns an empty string and not the attribute value.

CodePudding user response:

Assuming that buttonToggleGroupSelector returns something like cy.get('mat-button-toggle-group'), then you can do:

buttonToggleGroupSelector.should('have.attr', '[value]', 'myValue')

CodePudding user response:

You can use the invoke() method like so:

buttonToggleGroupSelector.invoke('attr', '[value]').should('eq', 'MyValue')

CodePudding user response:

I am mapping an input variable to the [value] attribute - the HTML you show is the source code, but Cypress sees the runtime version which has whatever input variable contains in place of [value].

So say your input variable was my-input-variable you would use

buttonToggleGroupSelector
  .should('have.attr', 'my-input-variable', 'myValue')
  •  Tags:  
  • Related