Giter Club home page Giter Club logo

vite-luxon-bug's Introduction

Vitest Luxon bug reproduction

  1. run npm install
  2. run the test with vitest npm run vitest
  3. run the test with jest npm run jest

Observe that the test fails with vitest but succeeds with jest.

Luxon DateTime instances are not instanceof DateTime when using vitest. Same test ran with Jest succeeds.

describe('LuxonUtils', () => {
    it('DateTime', () => {
        const utils = new LuxonUtils()
        const datetime = DateTime.now()
        expect(utils.date(datetime).isValid).toBeTruthy()
    });
})

I have located the problem to a small diffence between what TypeScript source of the date function in DateUtils is vs what their compiled source is. If I copy their source to my own project and let vite process that the test succeeds.

Their TypeScript:

if (value instanceof DateTime) {
    return value
}

Their JavaScript:

if (value instanceof luxon.DateTime) {
    return value
 }

When run through vitest, value is not a instance of luxon.DateTime and the code takes a wrong branch resulting in an invalid DateTime.

Is this problem a result of my vite/Typescript config, your bug, or a @date-io bug?

@date-io/luxon is an adapter library that standardizes multiple date libraries to the same API. It’s used by e.g. MUI. The bug doesn’t occur when using DateUtils in a React application in the browser.

vite-luxon-bug's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.