Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Store: Avoid Lodash get for getPostEdits #7381
This pull request seeks to refactor the
Verify unit tests pass:
This makes sense and is a definite improvement.
It highlights the risks of creating a raw state object in tests rather than dispatching actions to create a usable state. We can into this a lot on the addons-frontend project and created test helpers to initialise actual states rather than making up fake ones.
Is that something we could do for Gutenberg's tests? If yes I'll file a code quality issue, I just want to make sure it wasn't avoided for a technical reason...
@tofumatt This is an excellent point. It's come up a few times informally in the past. I agree it's not great that we have to manually craft the state shape when testing selectors, and it's been particularly painful when that state shape changes (and its resulting impact on selector tests).
I'd considered something similar to what you propose, where we could effectively just run the store reducer and merge in the tree paths (via
On the other hand, the one benefit to manually crafting state shape is that if in-fact these selectors depend on parts of the state shape existing, even if indirectly, it's important that these are considered in their own test cases. For example, it can be argued that our unit tests for
I agree it'd be good to create an issue to discuss this further.