Skip to content

How to write accurate tests for state mutation with custom equality implementation? #541

Answered by mbrandonw
mamouneyya asked this question in Q&A
Discussion options

You must be logged in to vote

Gotcha.

I can only think of two ways around this right now:

1.) You can create a wrapper type around State that provides a custom Equatable conformance so that you can restore the per-field equality check, and then in tests you can do something like .scope(state: Wrapper.init) on the TestStore to wrap state in that type. That will make it so that tests use the full equatable check.

2.) Alternatively, you can go back to the automatically synthesized Equatable and move the efficiency concerns to the application layer. You can write all your algorithms to not leverage Item's equatable conformance and instead just look at identifiers.

Neither are ideal, but I would lean towards the latter. In…

Replies: 7 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by mamouneyya
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #537 on May 10, 2021 15:38.