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

Always dispatch real state in tests instead of using raw state objects #7420

Closed
tofumatt opened this issue Jun 20, 2018 · 2 comments
Closed
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

Comments

@tofumatt
Copy link
Member

We have a lot of tests involving data/redux state that create a raw state object and test selectors, etc. against it. For example:

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.

@tofumatt tofumatt added the [Type] Code Quality Issues or PRs that relate to code quality label Jun 20, 2018
@danielbachhuber danielbachhuber added the [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. label Jun 21, 2018
@danielbachhuber
Copy link
Member

Related mozilla/addons#12480

@danielbachhuber danielbachhuber added this to the Bonus Features milestone Jun 21, 2018
@mtias mtias added Future and removed Future labels Oct 7, 2018
@youknowriad youknowriad modified the milestones: WordPress 5.x, Future Mar 25, 2019
@gziolo
Copy link
Member

gziolo commented Apr 23, 2019

It's similar to mozilla/addons#12480 which was closed with the following note:

In revisiting this and re-reading my comment at #6512 (comment) , the comment describes the encouraged approach to testing components. There should be no need to mock withSelect because one should not test the withSelect-bound component, but rather the component it wraps.

It can be reopened if it's still unclear or if there's a demonstrated benefit to an alternative approach, but I don't currently see any action item here.

Let's close this one as well. I also don't think that we should test bare components in unit tests and defer the rest to e2e tests which are great when covering more advanced use cases.

@gziolo gziolo closed this as completed Apr 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

5 participants