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

Date comparison isn't very useful #92

Open
antony opened this issue Feb 4, 2021 · 2 comments · May be fixed by #245
Open

Date comparison isn't very useful #92

antony opened this issue Feb 4, 2021 · 2 comments · May be fixed by #245

Comments

@antony
Copy link

antony commented Feb 4, 2021

Comparing dates with either .equal or .is results in some very obtuse output which makes it impossible to debug.

input

const { test } = require('uvu')
const assert = require('uvu/assert')

test('dates', () => {
    const a = new Date()
    const b = new Date(new Date().setMonth(5))
    assert.is(a, b)
})

test.run()

output

npx uvu
index.spec.js
✘   (0 / 1)

   FAIL  "dates"
    Expected values to be strictly equal:  (is)

        ++"2021-06-04T11:40:40.529Z"    (Expected)
        --                        {}    (Actual)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^
    at assert (/home/ant/Projects/uvutest/node_modules/uvu/assert/index.js:31:8)
    at Object.is (/home/ant/Projects/uvutest/node_modules/uvu/assert/index.js:39:2)
    at Object.handler (/home/ant/Projects/uvutest/index.spec.js:7:12)
    at Number.runner (/home/ant/Projects/uvutest/node_modules/uvu/dist/index.js:77:16)
    at exec (file:///home/ant/Projects/uvutest/node_modules/uvu/dist/index.mjs:131:39)
    at Module.run (file:///home/ant/Projects/uvutest/node_modules/uvu/run/index.mjs:13:8)
    at async /home/ant/Projects/uvutest/node_modules/uvu/bin.js:26:5



  Total:     1
  Passed:    0
  Skipped:   0
  Duration:  2.36ms
@talentlessguy
Copy link

with built-in assert.equal it converts both date objects to an ISO string and compares them

AssertionError [ERR_ASSERTION]: 2021-05-31T18:09:34.334Z == 2021-07-01T18:09:34.334Z

possible solution is to check if an object is an instance of Date and then apply toISOString()

@alextes
Copy link

alextes commented Mar 8, 2022

How do we feel about the suggested solution, would a PR be welcome? 😄

@ArtskydJ ArtskydJ linked a pull request Jun 9, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants