Zora doesn't recognize differences bewteen Maps
jwhitaker-swiftnav opened this issue · 2 comments
Related to #126, but opening a new issue to focus on a current specific gotcha:
import { test } from "zora";
test('example', () => {
const map1 = new Map([[1,1], [2,2]]);
const map2 = new Map();
t.eq(map1, map2);
}
Expected: this test should fail.
Actual: this test reports as successful.
I'm aware that this is going to be related to the library zora
is using for equality checking, but the current behaviour is certainly surprising to a zora
end user. Happy to contribute a PR if you can provide direction on how you'd like to solve this.
Cheers and thanks
Jarrad
Thanks a lot @jwhitaker-swiftnav
You are right. I had a look at fast-deep-equal
(the equality check library zora uses) and I think we should import the "es6 version" instead.
- you can start by adding a test in the pacakge "assert"
- then you should import the es6 version of fast-deep-equal here ie
import eq from 'fast-deep-equal/es6/index.js
I believe this should add the intended behaviour.
An alternative would be to wrap the fast-deep-equal equal
function within our own equal which detects whether the expected value is of type "Map" and then compare the entries instead. I would rather go for the first solution for now
If you want to go the extra mile. You can then add another PR on the reporting side (I am not sure Map diff are properly reported in both reporters -tap & diff)
Let me know if you need any help
cheers
got the checking going, the reporter is a bit of a rabbithole though. options seem to be reimplement the recursion of JSON.stringify in-house, use console.dir (meaning output is implementation-dependent), or pull in a dependency. Going with console.dir for now, because I don't want to spend a lot of effort before making sure you're ok with the approach.
EDIT: derp, console.dir doesn't give you the output.