Skip to content

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

@jwld

Description

@jwld

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions