GithubHelp home page GithubHelp logo

Comments (8)

astorije avatar astorije commented on June 12, 2024 1

Gotcha, thanks for the clarification!

Agreed, let's go with to.referenceEqual, at least while in v2, and if it needs changing in the future, it could be done in v3. But in the meantime and if possible, I'd rather keep .to.equal as a value equality check since it's more in the spirit of Immutable.js.

Thank you both for your help, looking forward to a PR! :)

from chai-immutable.

jakubzitny avatar jakubzitny commented on June 12, 2024 1

Sure -> #218 😉

from chai-immutable.

astorije avatar astorije commented on June 12, 2024

Hey @jakubzitny! Thanks for your feedback 🙏

I am totally open to a PR (I promise I will review it faster than I replied to your issue 😅). I prefer the option that maintains parity with the core of chai as this is pretty much what this plugin tries to achieve.

Wanna help? :)

from chai-immutable.

astorije avatar astorije commented on June 12, 2024

Actually, thinking more about this, I think .to.equal should stay the way it is because that's more in line with what Immutable.js is.
I think comparing references is an edge case in the world of Immutable.js (may I ask you for a use case?) so it would be unfortunate to tie it to the default meaning of .to.equal I think.

At the end of the day, assuming a and b are Immutable.js object, it shouldn't matter if expect(a).to.equal(b) ensures the references are the same, it's all value-based. Maybe not being able to assert reference equality is a sign that something might be fishy in the specs, but if there needs to be an escape hatch, then an explicit .to. referenceEqual is probably more appropriate. I'd be curious about use case before having a definitive opinion however.

from chai-immutable.

jankuca avatar jankuca commented on June 12, 2024

Our use case is covering shallow compare compatibility of our state. We have a store which returns a Map for instance and we want to ensure that it returns the same map instance on multiple invocations unless there were changes between getter calls. This allows us to optimize React component rerendering as the default comparison logic relies on reference equality.

from chai-immutable.

jakubzitny avatar jakubzitny commented on June 12, 2024

Thanks for the answers. Well, the use case is simple — I wanna be sure that a method (from flux store, a custom collection, or any class that stores Immutable data internally and returns them filtered/modified/mapped) returns always the same "modified" collection and does not re-create it on call every time (unless the data has changed).

Or as @jankuca mentioned above.

I think changing the .to.equal behaviour would be more "correct", but in order to cover most cases with Immutable.js and also to keep the backward compatibility, I would really be better to just implement to.referenceEqual.

from chai-immutable.

astorije avatar astorije commented on June 12, 2024

Hey @jakubzitny and @jankuca, quick follow-up: do you still intend to open a PR for this? I'd be happy to include it in the next release :)

from chai-immutable.

astorije avatar astorije commented on June 12, 2024

This has now be released as part of v2.1.0. Thanks again!

from chai-immutable.

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.