Giter VIP home page Giter VIP logo

Comments (10)

keithamus avatar keithamus commented on July 19, 2024 3

@pigulla this issue is still open. We're working on it πŸ˜„

from deep-eql.

keithamus avatar keithamus commented on July 19, 2024 3

@pigulla deep-eql 1.0 has been released, which fixes this, and will be used in chai 4.0 which is being released soon. Thanks for the issue!

from deep-eql.

pigulla avatar pigulla commented on July 19, 2024 2

I see this issue is closed, but

expect(new Set(['a'])).to.deep.equal(new Set(['b']))

still passes in the current version of Chai :(

from deep-eql.

keithamus avatar keithamus commented on July 19, 2024 1

Absolutely not bothering me, it's awesome that you're so keen to work on this all! I'm just bad at being organised at assigning myself to tickets.

If you are looking for stuff to work on, a couple of tickets you could definitely close down are:

chaijs/chai#407 - Add Proxy support to interfaces, so that unknown property access throws an error.
chaijs/chai#281 - Make ownProperty assertion more like property - change the context (flag(this, 'obj')) just like property does, and add a value second argument.

I will finish up with type-detect and deep-eql this weekend, hopefully get some time to make a same-error lib which will close a bunch of issues - and at some point in the week we could have a chat over Slack or Gitter or IRC about the roadmap, and what the rest of the plans are. Sound good?

from deep-eql.

keithamus avatar keithamus commented on July 19, 2024

Because Maps & Sets' keys aren't enumerable, one would need to specifically type detect if they are a Map or Set. To do this, you'd need to use type(a) === 'map' || type(a) === 'set' || type(a) === 'weakmap' || type(a) === 'weakset' || type(b) === 'map' || type(b) === 'set' || type(b) === 'weakmap' || type(b) === 'weakset' (type is a function already available) around L51, similar to how arguments is detected (L49-50). If you can do this in a cleaner way, great πŸ˜„

You'd then need to create a mapSetEqual function which compares them (see dateEqual for an example signature). mapSetEquals algo should probably go something like this:

// if the prototypes dont match, these wont be deep equal. return false early
if (a.prototype !== b.prototype) {
  return false;
}
ka = Array.from(a.keys()).sort(); // get the sorted keys for Map a
kb = Array.from(b.keys()).sort(); // get the sorted keys for Map b

if (iterableEqual(ka, kb) === false) { // iterableEqual already exists
  return false;
}

// iterate over the first maps keys
for (i = ka.length - 1; i >= 0; i--) {
  key = ka[i];
  // do a deep equality check on a and b's values of this key
  if (!deepEqual(a.get(key), b.get(key), m)) {
    return false;
  }
}

Tests would also need to be added to the test file for a complete PR.

from deep-eql.

lucasfcosta avatar lucasfcosta commented on July 19, 2024

Hi @keithamus, I will start working on this so we can solve chaijs/chai#394 next.

But I think we have to define what will be the behavior when it comes to WeakMaps and WeakSets. These data-structures are not iterable and we cannot get all elements from them.

This is what MDN says:

Because of references being weak, WeakMap/WeakSet keys are not enumerable (i.e. there is no method giving you a list of the keys). If they were, the list would depend on the state of garbage collection, introducing non-determinism. If you want to have a list of keys, you should maintain it yourself.

Are we going to use strict (===) comparison for these types?
What are your thoughts on this?

from deep-eql.

keithamus avatar keithamus commented on July 19, 2024

@lucasfcosta hold off on this - sorry. I've actually got a big refactor of deep-eql which should also solve this issue. I'll probably be submitting a PR in about 24 hours.

from deep-eql.

lucasfcosta avatar lucasfcosta commented on July 19, 2024

Ah, okay, no problem.
I hope I'm not bothering you with all those comments.

Let me know if you need any help with it πŸ˜ƒ

from deep-eql.

lucasfcosta avatar lucasfcosta commented on July 19, 2024

Sounds awesome!
I'll definitely take a look at these issues.
Thanks!

from deep-eql.

pigulla avatar pigulla commented on July 19, 2024

Duh. Can't read. My apologies.

from deep-eql.

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.