-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
should('have.data') caches data values #5655
Comments
Ran into this issue too. I would have expected the |
As per the documentation, You'll need to update the tests to requery the button: /// <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()
cy.get('button').should('have.data', 'count', 1)
})
it('gets count from data once', () => {
cy.get('button')
.click()
.click()
cy.get('button').should('have.data', 'count', 2)
})
}) |
Unfortunately, this doesn't solve the issue. In fact, your proposed solution with re-querying the button demonstrates the same issue as the initial reproduction steps. Also, if the button shouldn't be requeried, why does something like the below work? I think that the given reproduction is valid (i.e. it should work) it('updates text', () => {
cy.get('button')
.should('have.text', 'Hello world')
.click()
.should('have.text', 'abcdefg')
} |
This also doesn't handle the situation where you have something like: cy.get('html').should('have.data', 'eventCalled', true); Where eventually there should be a data prop added to that element. |
How could we workaround this? |
My current workaround:Instead of: function haveData(name: string, value: string) {
return ($el: Element) => {
expect($el[0].getAttribute(`data-${name}`)).to.be.equal(value);
};
} This works without any cache issue. |
Running into the same issue. We are using the data-test attribute to record data about the object used to create the element. However, after we get the element, make and save our changes, then check the data-test again it hasn't updated as it's caching the data values. Our workaround |
Same here: describe('Theme Switcher', () => {
beforeEach(() => {
cy.visit('/')
cy.get('[data-testid="body"]').as('body')
cy.get('[data-testid="theme-switcher"]').as('theme-switcher');
})
it.only('should change theme on click', () => {
cy.get('@body').should('have.data', 'theme', 'light')
cy.get('@theme-switcher').click({force: true})
cy.get('@body').should('have.data', 'theme', 'dark')
})
}) I ended up asserting by another way: cy.get('[data-theme="dark"]').should('exist') |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Current behavior:
The value of
data
is cached, such that the same values are returned for all futureshould('have.data')
Desired behavior:
The value should be updated so as to be able to assert changes in
data
attributesSteps to reproduce: (app code and test code)
https://github.com/iota-pi/cypress-bug-data-cache (using React)
Versions
Cypress: 3.6.1
Browser: Chrome 78 / Electron 73
OS: Windows 10
The text was updated successfully, but these errors were encountered: