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.setCookie always sets the same cookie if you pass the same options object #2701

Closed
maxwellhaydn opened this issue Oct 31, 2018 · 6 comments · Fixed by #2707
Closed

cy.setCookie always sets the same cookie if you pass the same options object #2701

maxwellhaydn opened this issue Oct 31, 2018 · 6 comments · Fixed by #2707

Comments

@maxwellhaydn
Copy link

maxwellhaydn commented Oct 31, 2018

cy.setCookie always sets the same cookie if you pass the same options object.

Current behavior:

Calling cy.setCookie multiple times always sets the same cookie as the first call if you pass the same options object each time. For example, the following sets two cookies named "foo" and "baz".

'use strict';
  
Cypress.Cookies.debug(true);

const options = {};

describe('cookie reuse', function() {
    it('sets the expected cookie', function() {
        cy.setCookie('foo', 'bar', options);
        cy.setCookie('baz', 'qux', {});
        cy.setCookie('apple', 'banana', options);

        cy.getCookie('foo').its('value').should('equal', 'bar');
        cy.getCookie('baz').its('value').should('equal', 'qux');
        cy.getCookie('apple').its('value').should('equal', 'banana');
    });
});

The Cypress log shows the names and values of all three cookies I tried to create, but the console shows that only two cookies were created:

setcookie-always-sets-same-cookie-when-options-object-is-the-same

The cookies section in the Chrome dev tools also shows only two cookies, "foo" and "baz":

setcookie-cookies-list

The "apple" cookie was never created. The call to cy.setCookie('apple', 'banana', options); just set the "foo" cookie again.

Desired behavior:

If I call cy.setCookie twice with different cookie names and values, but use the same options object in both calls, I expect to create two separate cookies.

Steps to reproduce:

See code snippet above.

Versions

Cypress 3.0.3, Mac OS 10.13.6, Chrome 70.0.3538.77

@jennifer-shehane jennifer-shehane added stage: investigating Someone from Cypress is looking into this stage: ready for work The issue is reproducible and in scope type: bug topic: cookies 🍪 and removed stage: investigating Someone from Cypress is looking into this labels Nov 1, 2018
@jennifer-shehane
Copy link
Member

Yes, this is a bug. We are mutating the object instead of cloning it as we should be.

@Knaledge
Copy link

Knaledge commented Nov 1, 2018

@jennifer-shehane - I ran into this recently as well. Any chance something like this might come out within the next release? Looking forward to a fix on this and #1321 (#2685 ?)

@lilaconlee
Copy link
Contributor

I'm taking a look right now! Not sure if it'll get in the next release, but we'll do our best.

@lilaconlee lilaconlee self-assigned this Nov 1, 2018
@jennifer-shehane

This comment has been minimized.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 7, 2019

The code for this is done in cypress-io/cypress#2707, 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 Nov 8, 2019

Released in 3.6.1.

@cypress-io cypress-io locked as resolved and limited conversation to collaborators Dec 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants