I am asserting cy.getCookie() only once in my code, but the Cypress runner shows the assertion happened twice. Though it is a very minor and low priority issue, it is not the most optimum as the logic for validating the cookie from cypress-runner.js is being called twice and adds to the execution time.
Cypress runner should show the ASSERT log only once for cy.getCookie('auth').should('exist')
// cypress/integration/login.spec.js
it('should login successfully with correct credentials and get auth cookie', () => {
cy.get('#loginForm').within(() => {
cy.get('#email')
.clear()
.type('[email protected]')
.get('#password')
.clear()
.type('Pass1234');
cy.contains('Login').click();
});
cy.title().should('eq', 'Crates for everyone! - Crate');
cy.url().should('eq', `${Cypress.config().baseUrl}/crates`);
cy.getCookie('auth').should('exist');
});

Both the ASSERTs print exactly the same message from the same line number of the Cypress runner source code cypress-runner.js:168422 to the DevTools console


Cypress:
"devDependencies": {
"cypress": "^4.1.0"
}
OS:
ProductName: Mac OS X
ProductVersion: 10.14.6
Browser:
Google Chrome is up to date
Version 80.0.3987.132 (Official Build) (64-bit)
Yeah...not sure why it's doing that.
This began happening in Cypress 4.0.0. There's a lot of changes in 4.0.0, but my complete guess is maybe it involves the Chai upgrade https://github.com/cypress-io/cypress/pull/2862.
spec.js
it('cookie verification', () => {
cy.visit('https://example.cypress.io/commands/cookies')
cy.get('#getCookie .set-a-cookie').click()
cy.getCookie('token').should('exist')
});



The below code does not log the assertion twice.
it('cookie verification', () => {
cy.visit('https://example.cypress.io/commands/cookies')
cy.get('#getCookie .set-a-cookie').click()
cy.getCookie('token').then((cookie) => {
expect(cookie).to.exist
})
});
HI @jennifer-shehane,
I had a look at this and it looks like the change in https://github.com/cypress-io/cypress/pull/2862 that is causing the assertion to run twice is:
https://github.com/cypress-io/cypress/pull/2862/files#diff-462c090a4a1cf87c581bae15f3af0d6aR111
It looks the same behaviour has been ported from the Coffescript to the Javascript version of asserting.
Example spec
it('cookie verification', () => {
cy.visit('https://example.cypress.io/commands/cookies')
cy.get('#getCookie .set-a-cookie').click()
cy.getCookie('token').should('exist')
});


I don't really understand why the code was introduced in the first place but it looks like most checks pass against the draft pull request I opened. Is there anything else you would like me to do or look at before requesting a review for the pull request?
@Tomastomaslol The PR will require tests to ensure that this is no longer logging twice in the UI. There's some idea of what these tests look like around command logs here: https://github.com/cypress-io/cypress/blob/develop/packages/driver/cypress/integration/commands/cookies_spec.js#L174:L174
@jennifer-shehane Thanks for your pointer. I opened a pull request that should fix the described issue. If you have a spare minute please let me know what you think of my proposed solution.
I really enjoyed working with the codebase and hopefully there will be other opportunities for me to contribute in the future!
Have a good Friday! 馃檪
The code for this is done in cypress-io/cypress#8276, but has yet to be released.
We'll update this issue and reference the changelog when it's released.
Released in 5.2.0.
This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.2.0, please open a new issue.
Most helpful comment
@jennifer-shehane Thanks for your pointer. I opened a pull request that should fix the described issue. If you have a spare minute please let me know what you think of my proposed solution.
I really enjoyed working with the codebase and hopefully there will be other opportunities for me to contribute in the future!
Have a good Friday! 馃檪