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

Strange bug with valid.expirationDate returning incorrect result in 2020 #127

Open
jwld opened this issue Aug 15, 2024 · 0 comments
Open

Comments

@jwld
Copy link

jwld commented Aug 15, 2024

General information

  • Library version: 10.0.0
  • Browser and OS: Chrome 127.0.6533.119 (64-bit) on MacOS 14.5

Issue description

Our test suites set the test suite time 2020-01-01 (using mockdate), and we have a test to check that valid.expirationDate will return isValid: true for "07/20". This works on versions 7 and below, but on version 8 up, it returns isValid: false.

Changing the tests to any year other than 2020 seems to work fine, but I can't work out why it doesn't work on that particular year.

To replicate it, install jest and mockdate, and then run the following test suite:

const valid = require('card-validator')
const MockDate = require('mockdate')

beforeAll(() => {
  MockDate.set('2020-01-01')
})

it('is valid', () => {
  const result = valid.expirationDate('07/20').isValid

  expect(result).toBe(true)
})

On versions 7 and below, this will pass as expected. But on versions 8 and above it fails.

Alternatively you can replicate it by simply setting your own system date to 2020-01-01, and then run console.log(valid.expirationDate('07/20')), which will incorrectly return isValid: false on versions 8 and above.

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

1 participant