2

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.

Fody
  • 23,754
  • 3
  • 20
  • 37
Hugo Seleiro
  • 2,467
  • 5
  • 26
  • 39
  • What does this return `buttonToggleGroupSelector` ? – Alapan Das Feb 03 '22 at 17:42
  • @AlapanDas, thank you buttonToggleGroupSelector .should('exist') .and($el => expect($el) .to.equal('MyValue')); - I Have tried like this and it returns , i already try to do $el.attr('value') to and no success , if i add the attribute value without the [] cypress can get the value, but not with brakets, and whiteout the brakets i cannot make the bind. – Hugo Seleiro Feb 03 '22 at 17:56

3 Answers3

5

When you use

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

Cypress is looking for a value property, but you want the value attribute

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

You can use the invoke() method like so:

buttonToggleGroupSelector.invoke('attr', '[value]').should('eq', 'MyValue')
Manuel Abascal
  • 5,616
  • 5
  • 35
  • 68
0

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

buttonToggleGroupSelector.should('have.attr', '[value]', 'myValue')
Alapan Das
  • 17,144
  • 3
  • 29
  • 52
  • it still returns undefined, but i notice if i declare without the brackets, i can get the value, but if i have no brackets i cannot make the bind. – Hugo Seleiro Feb 03 '22 at 17:58