Skip to content

should('have.data') caches data values #5655

Closed
@iota-pi

Description

@iota-pi

Current behavior:

The value of data is cached, such that the same values are returned for all future should('have.data')

Desired behavior:

The value should be updated so as to be able to assert changes in data attributes

Steps to reproduce: (app code and test code)

https://github.com/iota-pi/cypress-bug-data-cache (using React)

// App.js
import React from 'react';

class App extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      count: 0,
    };
  }

  render() {
    return (
      <button
        onClick={this.handleClick}
        data-count={this.state.count}
      >
        Hello world
      </button>
    );
  }

  handleClick = () => {
    this.setState({ count: this.state.count + 1 });
  }
}

export default App;
/// <reference types="Cypress" />

context('data caching', () => {
  beforeEach(() => {
    cy.visit('http://localhost:3000/')
  })

  it('fails to get count from data', () => {
    cy.get('button')
      .should('have.data', 'count', 0)
      .click()
      .should('have.data', 'count', 1)
  })

  it('gets count from data once', () => {
    cy.get('button')
      .click()
      .click()
      .should('have.data', 'count', 2)
  })
})

Versions

Cypress: 3.6.1
Browser: Chrome 78 / Electron 73
OS: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    pkg/driverThis is due to an issue in the packages/driver directorytype: unexpected behaviorUser expected result, but got another

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions