Coder Social home page Coder Social logo

Comments (12)

faassen avatar faassen commented on May 27, 2024 1

Note that:

chai.config.truncateThreshold = 0;

is a workaround. It still tries to show me useless diffs on how the underlying objects differ, though.

from chai-immutable.

faassen avatar faassen commented on May 27, 2024

Hm, I looked into a fix along these lines:

       var collectionRepr = (collection instanceof Collection ?
                              collection.toString() :
                              collection);

and then passing CollectionRepr, obj.toString() as the last two arguments into this.assert.

This failed and debugging it I found out that obj instanceOf Collection does not always hold true; there are Immutable objects where this is false. How to replicate it yet I don't know, but I have a set here that gives true to Immutable.isSet() but false toobj instanceof Collection`...

from chai-immutable.

faassen avatar faassen commented on May 27, 2024

But I suspect due to the Collection instance not being reliable I get an assertion failure where two immutable objects that should be the same are considered not to be...

from chai-immutable.

faassen avatar faassen commented on May 27, 2024

In the end I decided to forgo chai entirely for this kind of testing and replace it with a simple extension to node's assert:

assert.is = function(actual, expected, message) {
    if (!Immutable.is(actual, expected)) {
        assert.fail(actual, expected, message, "is", assert.is);
    }
};

so far it's much more reliable.

You could consider something similar: add an 'is' which assumes immutable objects, instead of trying to override equal to mean something in addition to its original meaning.

from chai-immutable.

astorije avatar astorije commented on May 27, 2024

Waouh @faassen, that's a detailed bug report! :-)
Thanks for sharing, give me a few days to finish what's on my priority queue and I'll get back to this to come up with a solution!

from chai-immutable.

kmckee avatar kmckee commented on May 27, 2024

Yes this is the same issue I reported on 24. Not sure how I missed this issue.

Here's what I've observed:

        it('does not give helpful test output?', () => {
            const expected = Map({
                entries: List.of('Trainspotting')
            });
            const actual = Map({
                entries: List.of('28 Days Later')
            });
            expect(expected).to.eql(actual);
        });

Yields the following output:

AssertionError: expected { Object (size, _root, ...) } to equal { Object (size, _root, ...) }

If I convert my immutables to regular JS objects, like below, I get output like what I was expecting:

        it('has helpful output with JS objects', () => {
            const expected = Map({
                entries: List.of('Trainspotting')
            });
            const actual = Map({
                entries: List.of('28 Days Later')
            });
            expect(expected.toJS()).to.eql(actual.toJS());
        });

Output:

AssertionError: expected { entries: [ 'Trainspotting' ] } to deeply equal { entries: [ '28 Days Later' ] }
      + expected - actual

       {
         "entries": [
      -    "Trainspotting"
      +    "28 Days Later"
         ]
       }

from chai-immutable.

astorije avatar astorije commented on May 27, 2024

@kmckee I'm working on a fix and it should land soon. Stay tuned.

from chai-immutable.

kmckee avatar kmckee commented on May 27, 2024

Awesome!

In the mean time, if anyone else is having the same problem, I've started to just call toJS() on my immutables when asserting with them, and then using POJOs for the expected values. I get nice output and I can easily remove them later with something like: grep -r expect.*toJS ./test

from chai-immutable.

astorije avatar astorije commented on May 27, 2024

@kmckee, 08edf4a should fix this issue. Can you confirm that this commit and subsequent commits after that do work in your case?
I'll release a patch version when you can confirm.

I know it's been a while, but that would be awesome to also have @faassen give his feedback on this. Let me know if you have anything to add, and thanks again fore reporting this in the first place :-)
Sorry I dropped the ball on you for months!

from chai-immutable.

kmckee avatar kmckee commented on May 27, 2024

Confirmed. Thanks a ton!!

Error message displayed is:
AssertionError: expected 'Map { "entries": List [ "Trainspotting", "28 Days Later" ] }' to equal 'Map { "entries": List [ "Traiinspotting", "28 Days Later" ] }'

from chai-immutable.

rogeriopvl avatar rogeriopvl commented on May 27, 2024

Great to see this fixed! 👍

When will this fix be published to npm?

from chai-immutable.

astorije avatar astorije commented on May 27, 2024

Oops, sorry @rogeriopvl, I was so busy I guess I dropped the ball after @kmckee replied...

Anyway, done: [email protected] is now published!

Thanks all for your patience, your helpful reports and encouragement, especially @faassen whom I ended up ignoring for 8+ months!

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.