Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zora doesn't recognize differences bewteen Maps #174

Closed
jwhitaker-swiftnav opened this issue Jan 5, 2023 · 2 comments
Closed

Zora doesn't recognize differences bewteen Maps #174

jwhitaker-swiftnav opened this issue Jan 5, 2023 · 2 comments

Comments

@jwhitaker-swiftnav
Copy link
Contributor

jwhitaker-swiftnav commented Jan 5, 2023

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

@lorenzofox3
Copy link
Owner

lorenzofox3 commented Jan 5, 2023

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.

  1. you can start by adding a test in the pacakge "assert"
  2. 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

@jwhitaker-swiftnav
Copy link
Contributor Author

jwhitaker-swiftnav commented Jan 9, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants