Comments (10)
@pigulla this issue is still open. We're working on it π
from deep-eql.
@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.
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.
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.
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.
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.
@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.
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.
Sounds awesome!
I'll definitely take a look at these issues.
Thanks!
from deep-eql.
Duh. Can't read. My apologies.
from deep-eql.
Related Issues (20)
- Dataview comparison ignores offsets HOT 2
- 'function' comparison
- objectEqual Sorts Keys Before Compare HOT 2
- Build failing due to change in error comparison algo HOT 2
- New version not automatically released HOT 4
- Assertion error does not state problematic parts for Maps HOT 1
- Comparison between uninitialized arrays fail HOT 3
- Get mismatch info? HOT 1
- Deep equality with a set depth
- Test project in Safari, Chrome, Firefox and Edge in the GitHub action
- URLSearchParams deep equal not working HOT 2
- Add TypeScript types
- Update karma package version to the newer one to support newer nodejs version HOT 1
- ChainAlert: new npm maintainer has published version 4.0.1 of package deep-eql
- Support for tc39/proposal-temporal HOT 1
- TypeError: Cannot convert a Symbol value to a string
- Donβt compare non-enumerable symbols HOT 4
- Feature request: Add possibility to exclude/omit keys when comparing objects HOT 2
- Loosely comparator with Set gives false result HOT 1
- Cannot reliably compare Ada-based URLs (Node.js v18.17.0 & newer) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deep-eql.