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

Option to ignore unspecified keys when using shouldEqualJson matcher #2298

Closed
Kantis opened this issue May 28, 2021 · 2 comments · Fixed by #2303
Closed

Option to ignore unspecified keys when using shouldEqualJson matcher #2298

Kantis opened this issue May 28, 2021 · 2 comments · Fixed by #2303
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones. good-first-issue 👶 Suitable for newcomers looking to contribute to the project. pinned 📌 Issues of high importance or that need to remain visible.
Milestone

Comments

@Kantis
Copy link
Member

Kantis commented May 28, 2021

I'd like an option for shouldEqualJson to ignore keys in actual that are unspecified in expected. It should probably be included for shouldNotEqualJson as well.

I think this could be achieved either by:

  • Expanding CompareMode with new modes: CompareMode.StrictIgnoringUnknownKeys and CompareMode.LenientIgnoringUnknownKeys
  • Adding a new flag to matcher signatures: ignoreUnknownKeys: Boolean
  • New matcher: shouldEqualSpecifiedJson? Better names? 😅

Following example should pass:

"""{ "a": 5, "timestamp": "2021-05-28T14:44Z" }""".shouldEqualJson("""{ "a": 5 }""", ignoreUnknownKeys = true) 
"""{ "a": 5, "timestamp": "2021-05-28T14:44Z" }""" shouldEqualSpecifiedJson """{ "a": 5 }"""
@Kantis Kantis added the enhancement ✨ Suggestions for adding new features or improving existing ones. label May 28, 2021
@ashishkujoy ashishkujoy added good-first-issue 👶 Suitable for newcomers looking to contribute to the project. assertions 🔍 Related to the assertion mechanisms within the testing framework. labels May 30, 2021
@Kantis
Copy link
Member Author

Kantis commented May 31, 2021

Starting a branch for this in my fork feature/kantis/2298-json-ignore-unknown ✌🏼

@stale
Copy link

stale bot commented Jul 30, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 30, 2021
@sksamuel sksamuel added pinned 📌 Issues of high importance or that need to remain visible. and removed wontfix labels Aug 2, 2021
@sksamuel sksamuel added this to the 5.0 milestone Aug 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. enhancement ✨ Suggestions for adding new features or improving existing ones. good-first-issue 👶 Suitable for newcomers looking to contribute to the project. pinned 📌 Issues of high importance or that need to remain visible.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants