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

Add support for mixed rendering #50

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Saegrov
Copy link

@Saegrov Saegrov commented Sep 27, 2017

Mixed rendering is a mode that works like shallow rendering, but where
you can specify a list of components you want to render even tho they
are deeply nested.

We have a use case where we are using shallow rendering and Cheerio for unit testing our Preact components. We are using a redux-connect like higher order component to connect some components to our global state.
When testing a component, that uses another component that is wrapped in a HOC, the shallow renderer stops at the HOC.

With mixed rendering we can white list components we want to render and test that the wrapped components are used correctly.

Mixed rendering is a mode that works like shallow rendering, but where
you can specify a list of components you want to render even tho they
are deeply nested.
src/index.js Outdated
nodeName = getComponentName(nodeName);
if (opts.shallow &&
(inner || opts.renderRootComponent===false) &&
!opts.alwaysRenderedComponents.includes(componentName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to use indexOf()!==-1 because this lib supports IE9+.

src/index.js Outdated
* @param {Array} alwaysRenderedComponents List of components that should be rendered with shallow rendering
* @param {Object} [context={}] Optionally pass an initial context object through the render path.
*/
let mixedRender = (vnode, alwaysRenderedComponents = [], context) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is size-constrained - would it be alright to add the alwaysRenderedComponents option, but not export another method (mixedRender)? That would keep things reasonably minimal.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! I'll update the PR.

@Saegrov
Copy link
Author

Saegrov commented Oct 17, 2017

@developit I've updated the PR, but kept the unit tests in a separate file. Do you want me to move them as well?

@developit
Copy link
Member

Hi @Saegrov! Sorry for the delay - happy to have the unit tests in their own file. I think this should be good to merge, just need to check the file size.

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

Successfully merging this pull request may close these issues.

None yet

2 participants