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

Unit testing plugin components that depend on Gutenberg data API? #6594

Closed
c-shultz opened this issue May 4, 2018 · 3 comments
Closed

Unit testing plugin components that depend on Gutenberg data API? #6594

c-shultz opened this issue May 4, 2018 · 3 comments

Comments

@c-shultz
Copy link

c-shultz commented May 4, 2018

I have some components in a Jetpack plugin (on this PR).

A couple components use withDispatch and withSelect. All is good when running in a browser with Gutenberg present, but unit testing my components becomes a challenge since those dependencies are out in Gutenberg.

I ended up splitting the component into two files: one with the core component that I ran tests against and the other that created the final higher order component using withDispatch and withSelect. That worked reasonably for that particular component, but feels a little hackish and probably won't work in every case.

Has anybody come up with a good approach for dealing with this? I fully suspect I'm missing a really obvious solution. :)

@gziolo
Copy link
Member

gziolo commented May 8, 2018

There is a similar issue opened: #3955. We plan to publish source code of all Gutenberg modules to npm as independent packages, so you could use them in your tests the same way it is done in Gutenberg. It should happen this month. I admit it might be a blocker for testing components as of today.

@gziolo
Copy link
Member

gziolo commented May 8, 2018

Let’s discuss details in #3955 😃

@gziolo gziolo closed this as completed May 8, 2018
@gziolo
Copy link
Member

gziolo commented May 8, 2018

In Gutenberg we also export a component without all thos HOCs applied and use it when unit testing. We always make sure selectors and actions are covered with tests and make sure withSelect and withDispatch don’t contain logic - only direct mapping from select calls to props or dispatch to props.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants