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.task passes null as default argument #5913

Closed
bahmutov opened this issue Dec 7, 2019 · 2 comments · Fixed by #8600
Closed

cy.task passes null as default argument #5913

bahmutov opened this issue Dec 7, 2019 · 2 comments · Fixed by #8600
Assignees

Comments

@bahmutov
Copy link
Contributor

bahmutov commented Dec 7, 2019

Seems cy.task calls task with null value instead of undefined if the argument was NOT specified in the spec call

Cypress v3.7.0

Reproduction in https://github.com/cypress-io/cypress-test-tiny/tree/default-arg-in-task cypress-io/cypress-test-tiny@c899a79

Imaging we have a task and use default value for its argument like

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  on('task', {
    hello(name = 'world') {
      console.log('hello ', name)

      return null
    }
  })
}

When we call cy.task('hello') I expect the terminal to print hello world but it prints

ET /__cypress/tests?p=cypress/integration/spec.js-609 200 2.326 ms - 619
GET /__cypress/tests?p=cypress/support/index.js-949 200 1.387 ms - -
hello  null

Expected behavior

cy.task methods should respect default arguments (we should not be passing null values)

@bahmutov bahmutov assigned bahmutov and chrisbreiding and unassigned bahmutov Dec 7, 2019
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Jan 2, 2020
@cypress-bot cypress-bot bot added stage: work in progress There is an open PR for this issue [WIP] and removed stage: ready for work The issue is reproducible and in scope labels Sep 17, 2020
@cypress-bot cypress-bot bot added the stage: pending release There is a closed PR for this issue label Sep 21, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 21, 2020

The code for this is done in cypress-io/cypress#8600, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot removed the stage: work in progress There is an open PR for this issue [WIP] label Sep 21, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 29, 2020

Released in 5.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v5.3.0, please open a new issue.

@cypress-bot cypress-bot bot removed the stage: pending release There is a closed PR for this issue label Sep 29, 2020
@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Sep 29, 2020
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.

2 participants