Always dispatch real state in tests instead of using raw state objects #7420
Labels
[Type] Automated Testing
Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
[Type] Code Quality
Issues or PRs that relate to code quality
Milestone
We have a lot of tests involving data/redux state that create a raw state object and test selectors, etc. against it. For example:
gutenberg/editor/store/test/selectors.js
Line 158 in c6a64a7
This is dangerous because it doesn't accurately test the way the app behaves in the real world. We should be creating a data store and dispatching real actions to create an accurate store state that we can test against. This means if we change our actions/reducers/etc. our tests will catch breaking changes.
My recommendation is not to manually run things like
createStore()
for every test (we tried doing that in addons-frontend and it led to mozilla/addons#10436), but create a (few) state/store creation helpers for tests. We did that on the addons-frontend and it made testing really great.The text was updated successfully, but these errors were encountered: