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

Default map matcher used by the match? directive can be confusing #20590

Closed
ilmotta opened this issue Jun 27, 2024 · 0 comments · Fixed by #20825
Closed

Default map matcher used by the match? directive can be confusing #20590

ilmotta opened this issue Jun 27, 2024 · 0 comments · Fixed by #20825
Assignees
Labels

Comments

@ilmotta
Copy link
Contributor

ilmotta commented Jun 27, 2024

Problem

Most devs in status-mobile using the lib https://github.com/nubank/matcher-combinators are surprised by the fact that the match? directive does not match expected map instances versus actual exactly. Unless a different matcher wraps the the expected map, match? will use the embeds matcher, which ignores unspecified keys in expected. This might be so surprising that can cause devs to waste a lot of time debugging why tests are passing when they should fail, until they realize this behavior is correct and documented in the library.

Implementation

We are currently using version 3.8.8, but version 3.9.0 has a new matcher called nested-equals. So the simplest solution is to upgrade the library and use this new matcher when needed.

The default behavior of match? is useful, but it's open for debate if the default behavior is what we want or if it wouldn't be better to be more strict by default. Probably being strict will cause less headaches and surprises, so another solution on top of the upgrade is to replace the default directive match? with one that's strict by default, and then the developer would still be able to override the default matcher when they want the embeds matcher.

Note

For the record, we have a guideline about using match? and why instead of =. https://github.com/status-im/status-mobile/blob/3ce6a86e9b9dba53c25265c243183d6884bb5aca/doc/new-guidelines.md#prefer-match-over--when-comparing-data-structures

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

Successfully merging a pull request may close this issue.

1 participant