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

Lodash (Capitalize) does not work as expected on Cypress #7222

Closed
victorFSL opened this issue May 4, 2020 · 3 comments · Fixed by #7255
Closed

Lodash (Capitalize) does not work as expected on Cypress #7222

victorFSL opened this issue May 4, 2020 · 3 comments · Fixed by #7255
Labels
pkg/driver This is due to an issue in the packages/driver directory type: unexpected behavior User expected result, but got another

Comments

@victorFSL
Copy link

victorFSL commented May 4, 2020

Current behavior:

On Cypress:

 _.capitalize("FOO BAR") => "FOO BAR"

Desired behavior:

On the lodash website:

 _.capitalize("FOO BAR") => "Foo bar"

Test code to reproduce

const { _ } = Cypress

console.log(_.capitalize("FOO BAR")) => "FOO BAR"

Versions

Cypress version: 4.4.0
Browser: Chrome 83

When I look at the documentation cypress is on lodash 4.17.15 since version 3.4.1. Which is the lastest version of lodash and the one used in the website.

@jennifer-shehane
Copy link
Member

Yeah, I can confirm this behavior.

Why

So, what I've discovered is happening here is that we seem to have patched one of the lodash methods with underscore.string methods.

I can't find the exact git blame, since it spans across old repos, but I'm 95% sure that this comment is from @brian-mann about the use of overriding lodash capitalize with underscore.capitalize:

// its mo' better the lodash version

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/config/lodash.js#L11:L11

This appears to be the only lodash method we are overriding (although we added some new methods from underscore.string).

I think this is completely unexpected behavior, especially since this is not documented anywhere. I'll have to discuss with the team how to handle this - if this would be considered a breaking change or a 'fix' to change.

To Reproduce

package.json

{
  "devDependencies": {
    "cypress": "4.5.0",
    "lodash": "^4.17.15",
    "underscore.string": "^3.3.5"
  }
}

spec.js

const lodash_ = require('lodash')
const underscoreString_ = require('underscore.string')

it('works', () => {
  expect(lodash_.capitalize('FOO BAR')).to.eq('Foo bar')           // passes
  expect(underscoreString_.capitalize('FOO BAR')).to.eq('FOO BAR') // passes
  expect(Cypress._.capitalize('FOO BAR')).to.eq('FOO BAR')         // passes
})

@cypress-bot cypress-bot bot added the stage: proposal 💡 No work has been done of this issue label May 5, 2020
@jennifer-shehane jennifer-shehane added type: unexpected behavior User expected result, but got another pkg/driver This is due to an issue in the packages/driver directory labels May 5, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: proposal 💡 No work has been done of this issue stage: work in progress labels May 7, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 8, 2020

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

@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 8, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 20, 2020

Released in 4.6.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg/driver This is due to an issue in the packages/driver directory type: unexpected behavior User expected result, but got another
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants