should('have.data') caches data values
See original GitHub issueCurrent 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:10 (2 by maintainers)
Top Results From Across the Web
What Is Cached Data? Why & How Should You Clear It? - Okta
Common reasons for doing so include: Speed and performance. A full cache needs memory, and if you're full, a bogged down memory doesn't...
Read more >Caching Best Practices | Amazon Web Services
However, other times, data is best cached in a format that combines multiple records together. Because caches are simple key-value stores, you might...
Read more >What is Cached Data? What does Clear Cache Mean and ...
A cache's primary purpose is to speed up retrieval of web page resources, decreasing page load times. Another critical aspect of a cache...
Read more >All things caching- use cases, benefits, strategies, choosing a ...
Since the application writes only to the caching service, it does not need to wait till data is written to the underlying data...
Read more >Caching guidance - Azure Architecture Center | Microsoft Learn
Caching can dramatically improve performance, scalability, and availability. The more data that you have and the larger the number of users that need...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This will be resolved in Cypress 12, coming soon to an
npm
near you (by soon, I mean “early December”). See #7306 and more specifically https://github.com/cypress-io/cypress/pull/24628 for details.My current workaround:
Instead of:
.should('have.data', 'key', 'value')
Do:.should(haveData('key', 'value'))
This works without any cache issue.