shouldjs / equal Goto Github PK
View Code? Open in Web Editor NEWDeep equality comparison implementation for should.js
License: MIT License
Deep equality comparison implementation for should.js
License: MIT License
const a = new Set([1])
const b = new Set()
eq(a, b) // fails
eq(b, a) // does not fail
Right now WeakSet and WeakMap are considered to behave the same as Set and Map. This is however not true and comparing these types will result in the following error. It is actually not possible to check for WeakSet or WeakMap equality at all. It is only possible to check if a entry itself exists or not.
const a = new WeakSet()
const b = new WeakSet()
eq(a,b) // TypeError: a.entries is not a function
at EQ._check_object_weak-set (/home/repos/general/equal/cjs/should-equal.js:281:23)
at EQ.check0 (/home/repos/general/equal/cjs/should-equal.js:130:7)
at EQ.check (/home/repos/general/equal/cjs/should-equal.js:90:12)
at eq (/home/repos/general/equal/cjs/should-equal.js:312:29)
Is it possible to work ES6 set support into this? I would love to be able to compare 2 sets, and see which members differ.
Thanks for the outstanding work, regardless!
In Maps it is possible to use objects as keys and even to use the same key multiple times.
The latter will fail right now.
const a = new Map([[{}, {a:6}], [{}, {a:5}]])
const b = new Map([[{}, {a:6}], [{}, {a:5}]])
eq(a, b) // failure
[ EqualityFail {
a: 6,
b: 5,
reason: 'A is not equal to B',
path: [ 'a' ],
showReason: false },
EqualityFail {
a: 5,
b: 6,
reason: 'A is not equal to B',
path: [ 'a' ],
showReason: false } ]
The following code reproduces the issue:
require("should");
const a = (new Uint8Array([1])).buffer;
const b = (new Uint8Array([2])).buffer;
console.log(a.constructor, b.constructor);
// [Function: ArrayBuffer] [Function: ArrayBuffer]
console.log(a.should.deepEqual(b)); // doesn't throw
/*
Assertion {
obj: ArrayBuffer { [Uint8Contents]: <01>, byteLength: 1 },
anyOne: false,
negate: false,
params: {
operator: 'to equal',
expected: ArrayBuffer { [Uint8Contents]: <02>, byteLength: 1 },
message: undefined,
details: '',
showDiff: true
}
}
*/
const c = new Uint8Array([1]);
const d = new Uint8Array([2]);
console.log(c.constructor, d.constructor);
// [Function: Uint8Array] [Function: Uint8Array]
console.log(c.should.deepEqual(d)); // throws
The first deepEqual should throw as well, but it doesn't. I'm using shouldjs 13.2.3
Would it be possible to add an option which would compare primitives and boxed values of the same type with ==
? I would not want any type conversions, only for these tests to be swapped when the option is enabled.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.