Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cy.should('have.value', someValue) always fails when applied to <progress> or <meter> elements #7603

Closed
LisaManresa opened this issue Jun 5, 2020 · 4 comments · Fixed by #7621
Labels
type: regression A bug that didn't appear until a specific Cy version release v4.6.0 🐛 Issue present since 4.6.0

Comments

@LisaManresa
Copy link

LisaManresa commented Jun 5, 2020

Current behavior:

cy.should('have.value', someValue) always fails when testing <progress> or <meter> elements. This is regardless of whether the value passed to the assertion is a String or Number.

Assertion results in expected '<progress#progressEl>' to have value '50', but the value was 50
Screen Shot 2020-06-05 at 8 58 54 AM

Desired behavior:

When applied to a <progress> or <meter> element, the cy.should('have.value', someValue) should behave the same way it does for <input> elements.

Test code to reproduce

HTML

<progress id="progressEl" max="100" value="50">50%</progress>

Test

cy.get('#progressEl').should('have.value', 50);

Comparison between have.value asserted on <input> vs <progress>/<meter>, as well as a comparison with have.attr can be found here: https://github.com/LisaManresa/cypress-test-tiny

Versions

Cypress 4.6.0

@jennifer-shehane
Copy link
Member

jennifer-shehane commented Jun 8, 2020

@LisaManresa Thanks for providing a reproducible example! This looks to be a regression introduced in 4.6.0 very likely within #7315

A progress element's value actually accepts a floating point number, as opposed to input values which accept strings, which is what the main use case was considering with the change that was made in 4.6.0. So I think it wasn't taking progress and meter HTML elements into account.

<html>
<body>
<progress max="100" value="70">70%</progress>
<meter min="0" max="100" low="33" high="66" optimum="80" value="50">
  at 50/100
</meter>
</body>
</html>
describe('progress', () => {
  it('test', () => {
    cy.visit('index.html')
    // ❗️fails in 4.6.0 - passes in 4.5.0
    cy.get('progress').should('have.value', 70) 
  })
  
  it('test', () => {
    cy.visit('index.html')
    // fails in 4.6.0 and 4.5.0
    cy.get('progress').should('have.value', '70') 
  })
  
  it('test', () => {
    cy.visit('index.html')
    // passes in 4.6.0 and 4.5.0
    cy.get('progress').invoke('val').should('eq', 70) 
  })
  
  it('test', () => {
    cy.visit('index.html')
    cy.get('progress').should(($el) => {
      // passes in 4.6.0 and 4.5.0
      expect($el.val()).to.eq(70)
    })
  })
})

describe('meter', () => {
  it('test', () => {
    cy.visit('index.html')
    // ❗️fails in 4.6.0 - passes in 4.5.0
    cy.get('meter').should('have.value', 50)
  })

  it('test', () => {
    cy.visit('index.html')
    // fails in 4.6.0 and 4.5.0
    cy.get('meter').should('have.value', '50')
  })

  it('test', () => {
    cy.visit('index.html')
    // passes in 4.6.0 and 4.5.0
    cy.get('meter').invoke('val').should('eq', 50)
  })

  it('test', () => {
    cy.visit('index.html')
    cy.get('meter').should(($el) => {
      // passes in 4.6.0 and 4.5.0
      expect($el.val()).to.eq(50)
    })
  })
})

Screen Shot 2020-06-08 at 3 34 53 PM

Workaround

Downgrade to 4.5.0 or use one of the other passing methods above to test the value outside of the .should() chainers.

@jennifer-shehane jennifer-shehane added v4.6.0 🐛 Issue present since 4.6.0 type: regression A bug that didn't appear until a specific Cy version release labels Jun 8, 2020
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jun 8, 2020
@jennifer-shehane
Copy link
Member

<li> also accepts a value with a number type. So, there need to be certain elements taken into account https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes:

Screen Shot 2020-06-08 at 3 51 42 PM

Elements that accept number type value:

  • progress
  • meter
  • li

Elements that accept string type value:

  • input
  • button
  • option
  • param
  • data

@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress There is an open PR for this issue [WIP] labels Jun 8, 2020
@cypress-bot cypress-bot bot added stage: pending release There is a closed PR for this issue and removed stage: needs review The PR code is done & tested, needs review labels Jun 9, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 9, 2020

The code for this is done in cypress-io/cypress#7621, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Jun 23, 2020

Released in 4.9.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v4.9.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Jun 23, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Jun 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: regression A bug that didn't appear until a specific Cy version release v4.6.0 🐛 Issue present since 4.6.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants