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

Validation fails when x => y where y is 0 #1091

Closed
runofthemillgeek opened this issue Mar 20, 2018 · 1 comment
Closed

Validation fails when x => y where y is 0 #1091

runofthemillgeek opened this issue Mar 20, 2018 · 1 comment

Comments

@runofthemillgeek
Copy link

Here's the test case that mimics the issue I encountered:

it.only('shouldn\'t fail if an option implies on a number option where value is 0', () => {
  let failCalled = false

  const argv = yargs('--bool --num 0')
  .boolean('bool')
  .number('num')
  .implies('bool', 'num')
  .fail((msg) => {
    failCalled = true
  })
  .argv

  failCalled.should.be.false
  expect(argv.bool).to.be.true
  expect(argv.num).equals(0)
})

Running mocha, this prints the following:

  validation tests
    implies
      1) shouldn't fail if an option implies on a number option where value is 0


  0 passing (57ms)
  1 failing

  1) validation tests implies shouldn't fail if an option implies on a number option where value is 0:

      AssertionError: expected true to be false
      + expected - actual

      -true
      +false

      at Context.it.only (test\validation.js:171:28)

This should clearly not be failing as 0 is a valid number but on my project, I get implication error when 0 is passed as the value. Note that other values work fine. I believe this is because the code relies on JS coercion to determine if the implied key exists or not. I have already tried and made a quick-fix which currently passes all the tests including this one but JIC, need to know if I'm missing something regarding this issue.

@shadowspawn
Copy link
Member

This has hopefully been fixed by #1985

Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants