Giter Site home page Giter Site logo

Comments (4)

werkshy avatar werkshy commented on July 28, 2024 1

Maybe you could reduce the strictness level of your assertion like with toMatchObject, it should pass even if it is a proxy.

🙏 @Sytten thank you! toMatchObject() works here, and is probably what I should have been using all along. I am going to close this issue since that is the more idiomatic expectation.

from jest-mock-extended.

Sytten avatar Sytten commented on July 28, 2024

It was most likely a side effect pf #60
Since this was introduced to fix a bug I expect it will stay that way.
Strict equality on JS objects that are not primitives is always brittle at best.
I would suggest either creating an operator for jest for dates or just comparing the timestamp that underlines the date.

from jest-mock-extended.

werkshy avatar werkshy commented on July 28, 2024

I appreciate your comment @Sytten and thank you to all the contributors. This is a useful package.

If I was just testing the value of createdAt I could compare the underlying timestamp, but in this case I want to assert on the structure of this query object (Sequelize) that I'm building up. I don't even know how to write an expectation that this part of the object is a proxied Date that matches the expected timestamp.

either creating an operator for jest for dates

I'm not sure what this would look like, can you think of something similar to base that on?

I looked at #60 and I think I may have experienced that bug a few months ago and just lived without the assertion I was trying to make because I couldn't understand the cause at the time. If this new issue isn't a bug, it at least feels like a limitation and it is surprising to me, as a user (the surprise is that I set createdAt as a Date, but it was converted into a Proxy.)

Is there any way to more generally have a Proxy for a Date pass an equality expectation with a Date? If not, maybe I just need to embrace the workaround of setting createdAt: mock<Date>() in this case.

from jest-mock-extended.

Sytten avatar Sytten commented on July 28, 2024

Maybe you could reduce the strictness level of your assertion like with toMatchObject, it should pass even if it is a proxy.
To me it is no surprising behaviour since it is within a mock, otherwise you would need a spy or a partial mock (which are not a thing in this lib right now).

from jest-mock-extended.

Related Issues (20)

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.